Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLucas Alexander
3,528 Pointscls(ptrn) just recreates the initial string since cls() runs the original letter init code
Just a bit confused by the question and what it's expecting to return. I get that it's looking for a class instance of Letter, but sending in the pattern and returning the newly constructed pattern though cls() just basically resets that work. Obviously can't send back just the new pattern as it's just a list and not a class instance.
I notice in the question it mentions pattern([...]), is it expecting an instance of a pattern object? I don't know, just a bit confused about what the question is asking for.
class Letter:
def __init__(self, pattern=None):
self.pattern = pattern
def __iter__(self):
yield from self.pattern
def __str__(self):
output = []
for blip in self:
if blip == '.':
output.append('dot')
else:
output.append('dash')
return '-'.join(output)
@classmethod
def from_string(cls, str_pattern):
ptrn = []
for val in str_pattern.split('-'):
if val == 'dash':
ptrn.append('-')
elif val == 'dot':
ptrn.append('.')
return cls(ptrn)
class S(Letter):
def __init__(self):
pattern = ['.', '.', '.']
super().__init__(pattern)
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsYou are SO close! The dash should be an underscore instead of a hyphen.
Post back if you need more help. Good luck!!!
KRIS NIKOLAISEN
54,972 PointsFor a dash you should append an underscore. You are currently appending a hyphen.
Lucas Alexander
3,528 PointsLucas Alexander
3,528 PointsI am become silly, destroyer of worlds.
Thank you kindly, hahah!