Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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,094 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,094 Points

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