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 Object-Oriented Python Advanced Objects Iterable Album

Here is a class called Album that holds a list of songs. Add an _iter_ method to our Album class and use yield or yie

Here is a class called Album that holds a list of songs. Add an iter method to our Album class and use yield or yield from so the songs in our album can be iterated through

I am struggling with this please help

iter_album.py
class Album:
    def __init__(self):
        self.songs = []
    def add(self, song):
        self.songs.append(song)
    # insert your code here
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, string):
        stringList = string.split('-')
        patternList = []
        for blip in stringList:
            if (blip.lower() == 'dash'):
                patternList.append('_')
            elif (blip.lower() == 'dot'):
                patternList.append('.')
            else:
                pass
                return cls(pattern=patternList)



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

2 Answers

Josh Keenan
Josh Keenan
19,652 Points

You don't need to add any of this:

 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, string):
        stringList = string.split('-')
        patternList = []
        for blip in stringList:
            if (blip.lower() == 'dash'):
                patternList.append('_')
            elif (blip.lower() == 'dot'):
                patternList.append('.')
            else:
                pass
                return cls(pattern=patternList)



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

Remove it as it has nothing to do with the challenge.

Lee Vaughn
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Lee Vaughn
Treehouse Teacher

Hi Sinazo!

In addition to what Josh mentioned above having some extra code that you don't need for this challenge, in your _iter_ method you want to iterate through the songs in the album, not "pattern".

I hope that helps!