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 trial


Andrei Oprescu
Andrei Oprescu
9,547 Points

I don't know what I did wrong

So i have this question on one challenge:

Let's practice using @classmethod!

Create a class method in Letter named from_string that takes a string like "dash-dot" and creates an instance with the correct pattern (['_', '.']).

and my code is at the bottom.

Can someone tell me what I missed?


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 == '.':
        return '-'.join(output)

    def from_string(cls, blip_list):
        blips = []
        for blip in blip_list:
            if blip == 'dot':
            elif blip == 'dash':
        return blips

class S(Letter):
    def __init__(self):
         pattern = ['.', '.', '.']

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Andrei Oprescu, you close to a solution. Three items need fixing.

  • the results of blip_list.split('-') isn't assign to a variable so it is lost. You reassign the results back to blip_list of needed.
  • your dash string should be an underscore (_) instead of a hyphen (-)
  • the challenge asks for and instance be returned, not the list. Instead use the list you created to create a new instance. Hint you can use the cls() available.

Post back if you need more help. Good luck!!!

Nik Omel
Nik Omel
Python Web Development Techdegree Student 7,496 Points
    def from_string(cls, words):
    output = []
    words = words.split("-")
    for word in words:
        if word == "dot":
        elif word == "dash":
    return cls(output)```

What am I doing wrong?
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Please do not simply post cut-and-paste solutions. Instead try to address what issues in the original post. Thanks.