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

Rob Narayana
Rob Narayana
7,767 Points

Pretty sure my output is correct, not sure why i'm not passing the code challenge 1 of 2

Here's my code:

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"], ] for members in musical_groups: ", ".join(str(musical_groups)) print(members)

I must be missing some concept to grasp here. Has anyone successfully finished this code challenge?

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"],
]
for members in musical_groups:
    ", ".join(str(musical_groups))
    print(members)

1

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

for members in musical_groups : print(", ".join(members))

2

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

for members in musical_groups : if len(members) == 3: print(", ".join(members))

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

Looks like you get the concept of join() method, let's build on that.

The way you wrote your loop was spot-on-- good work!

The join() method needs a little work, since we want to join members into a string (like mystring in the example below).

for members in musical_groups:
    # each time we go through the loop, members is set equal to a list of members
    # lets JOIN the members with commas and CAPTURE it into mystring
    mystring = ", ".join(members)
    # now, print it out.
    print(mystring)

On part two-- the Challenge asks for ONLY trios.

for members in musical_groups:
    # each time we go through the loop, members is set equal to a list of members
    # lets JOIN the members with commas and CAPTURE it into mystring
    # PART 2, print only the TRIOS
    if len(members) == 3:
        mystring = ", ".join(members)
        # now, print it out.
        print(mystring)
Rob Narayana
Rob Narayana
7,767 Points

Ahhhhhhhhh. I see what i did wrong there, thank you so much!