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

Python

OOP - Challege - Letter/Pattern

Whenever I'm working on one of these code challenges i try to work on them in the workspaces so i can toy with them a little easier - I've added the code im trying to use at the moment but the output im getting in workspaces is : str(Letter("dash-dot"))
'dash-dash-dash-dash-dash-dash-dash-dash'

Edit - so obviously there was no way it was looping and eachh letter was being iterated over to be checked if it was a . or -, of which none of the 8 characters are . ,, so we get 8 "dash"... I'll continue to update what i get to until someone replies or i find the correct answer

Any help appreciated

morse.py
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, words):
        output= []
        for thing in words:
            if thing ==  'dash':
                output.append('-')
            if thing == '-':
                output.append('')
            else:
                output.append('.')
        return cls(output)



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