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 trialgurveer aulakh
2,800 Pointsmultidimensional musical quiz help!!
PLs, help me solve this problem. I ran out of all the possibilities. pls, help y'all.
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 group in musical_groups:
print(", ".join(group))
if len(musical_groups) == 3:
print(group)
2 Answers
Johannes Scribante
19,175 PointsGurveer, if you look at your code and you go through it systematically, what is your code saying?
for group in musical_groups:
Loop through each item in musical groups. That would give us being through each iteration of the loop
> ["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"]
Each item is therefore a list on its own.
Then you are saying
print(", ".join(group))
Now that we are currently looking at all of the lists in musical_groups, we will be printing the following
> "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"
Only after you have printed all your lists (and nicely formatted) are you checking the condition to see if a group only contains 3 items.
That is where Henrik Christensen was trying to guide you.
# loop through musical_group
# condition to check if group has 3 items
# then print the formatted group
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points# loop here
# if group has 3 members
# print that group
That's all you need :-)
gurveer aulakh
2,800 Pointsthat what I did. I have a loop then if statement and after that print statement.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsNo, it's not what you're doing
# loop here
for group in musical_groups:
# if group has 3 members
if len(group) == 3:
# print that group
print(', '.join(group))