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

magic methods [Solved]

So after looping through the pattern attribute, I am not sure how to use the .joint() function to return the required output

morse.py
class Letter:
    def __init__(self, pattern=None):
        self.pattern = pattern
    def __str__(self): # defining a __str__ method
        for i,j in pattern: # looping through the pattern attribute
            if i =="." and j=="_": # i should be equal to "." and j equal to "_" while looping through the pattern attribute
                result= .joint() # using .joint() to join i and j to be returned as "dot-dot-dot"


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

Thanks Nathan , I see where I made mistakes

1 Answer

    def __str__(self):
        output = [] #Empty string to add item insides
        for each_letter in self.pattern: #Looping through each letter in pattern
            if each_letter == ".":
                output.append("dot") #Adding items to empty list
            elif each_letter == "_":
                utput.append("dash")
            return "_".join("output")