Welcome to the Treehouse Community
Looking to learn something new?
George Clement2,816 Points
I am not sure what to do with this one... I know the replaces I am using are ugly but not sure why they are failing
class Letter: def __init__(self, pattern=None): self.pattern = pattern def __string__(self): def __str__(self): string_copy1 = self.pattern string_copy2 = string_copy1.replace(".", "dot") string_copy3 = string_copy2.replace("_", "dash") string_copy4 = string_copy3.replace(" ", "-") return string_copy4 class S(Letter): def __init__(self): pattern = ['.', '.', '.'] super().__init__(pattern)
Chris FreemanTreehouse Moderator 67,986 Points
Though your solution is not as efficient as a single pass
for loop, it would work with the following corrections:
self.patternis a list, so it should be converted to a string before using executing the replacements:
string_copy1 = " ".join(self.pattern)
- The extraneous method
__string__is incomplete. Remove or add a
You can further simplify your solution by
"-".join()so the space-to-hyphen is already done.
- no need to create a new string "copy", you may reassign the result to
stringwhich overwrites the previous value
Post back if you need more help. Good luck!