Welcome to the Treehouse Community
Looking to learn something new?
Let's make our Letter class better for our Morse code challenge. Add an __iter__ method to the Letter class so the lette
Having some trouble with this challenge. I tried to implement the corrections that were recommended to Steve Hunter in his question about this challenge.. but it hasn't worked for me. Can anyone give me some advice on how to pass this challenge? thank you
class Letter: def __init__(self, pattern=None): self.pattern = pattern def ___str___(self): output =  for c in self.pattern: if c == '.': output.append('dot') elif c == '_': output.append('dash') return "-".join(output) class S(Letter): def __init__(self): pattern = ['.', '.', '.'] super().__init__(pattern)
Hey bro, You've got a triple underscore thing going on with your str function.
Are you putting your code in the class Letter part or in the class S(letter)? When I first did this challenge it accidentally put my code at the bottom of S(letter) and I got the same error as you. Then I put it in the class Letter and it passed.
def __iter__(self): yield from self.pattern
Should pass if it is put in the class Letter but it will say Letter isn't iterable if its put in the class S(Letter). Hope that helps you.
Hi D Elis. The teacher gives example code where we build our own list from the ground up:
def __iter__(self): for item in self.slots: yield item
This snippet below is functionally identical:
def __iter__(self): yield from self.slots
Of course slots was specific to the example and not this challenge. I was able to pass it months ago, and just now. This OOP course was the toughest Python course I took... until the datetime course... and then until the regex course. But never mind those for now :)
Please let me know if I can help out further.
I'm sorry to hear this :( Can you tell me what the error says?
Also, if you've tried running it in your console, does that tell you which line the error is on?
Jan Durcak12,662 Points
Hey guys, What can you do with this piece of code, how can you iterate in you python console after is updated(python console)?