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.

Python

plz help can't understand what to do to pass tihs question?

i'am trying to solve this from past 2 days but i'am unable to pass plz help me with your code ...

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern

    @from_string
    def create_dash(cls,string):
        string_list = []
        str = string.split("-")
        for element in string_list:
            if element == "dash":
                string_list.append("-")
            else:
                string_list.append(".")





    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)


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

1 Answer

Steven Parker
Steven Parker
215,960 Points

You're getting close, but there's a few issues yet:

  • the new method is named "create_dash", but the instructions ask for one named "from_string"
  • the method is marked as "@from_string" but the instructions ask for a "@classmethod"
  • "dash" is converted to a hyphen ("-") but the instructions say to make them underscores ("_")
  • the method should return a new instance with the created pattern loaded

how to return a newinstance with the created pattern loaded

Steven Parker
Steven Parker
215,960 Points

Since the current class is passed in as "cls", it takes the pattern as an argument, and you've created the new pattern in "string_list":

        return cls(string_list)