Python Introducing Lists Build an Application Multidimensional Musical Groups

Chris Drummond
Chris Drummond
1,315 Points

Multidimensional Lists - AssertionError: Task Number 2: Print only groups with 3 band members

I have looked at other questions and tried their responses but I cannot seem to get this code to work.

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
for band in musical_groups:
    seperator = ", "
    bands = seperator.join(band)
    print(bands)

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

1 Answer

Mel Rumsey
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Hey Chris Drummond, you are close here, but we really only need to add one line of code to your previous statement:

for band in musical_groups:
                                # <--- Add an *if* statement here checking if the length of band is equal to 3: then do this v v v
    seperator = ", "
    bands = seperator.join(band)
    print(bands)

We only want to print bands that have 3 people, so changing your previous code to operate only if there are 3 people will pass in this case.

Hope this helps! Happy coding :D