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 Introducing Lists Build an Application Multidimensional Musical Groups

Charles McKelvey
Charles McKelvey
2,276 Points

Why does it say 'File "", line 54, in test_output' when I've only used 14 lines of code?

I'm trying to get this For Loop to work by doing what we did in the wishlist.py Making a function "display_groups(members)" and going through each member via: for member in members: s = ', ' print(s.join(members))

In my head it makes sense but it keeps throwing an error. Then when I tried using this in the Workspaces, it threw me; <function display_groups at 0x7fb5c38a5e18>

There also isn't any hints/help that goes with this so I'm a bit stuck.

groups.py
musical_groups = [
    ["Ad Rock", "MCA", "Mike D."],
    ["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"],
    ["Salt", "Peppa", "Spinderella"],
    ["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"],
    ["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"],
    ["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"],
    ["Run", "DMC", "Jam Master Jay"],
]
# Your code here
def display_groups(members):
    for member in members: 
        s = ", "
        print(s.join(member))

1 Answer

Charles McKelvey
Charles McKelvey
2,276 Points

I figured it out and here is what I did: for group in musical_groups: print(', '.join(group))

However, I'd still like to understand how that works. I've always had a hard time with for loops. Does it do it's own natural iterations? Is it doing a natural i++ in the background that we can't see? I'm used to a format where you describe the whole system of events in this format (I believe this is from JavaScript) :

for(i = 0; i < 10; i++): #your code here

So seeing all of this done for me in the background adds a level of confusion and uncertainty.