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 trialBalazs Ferencz
4,993 PointsWhat is the solution please?
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: members = ", ".join(members) i = 0 num = len(members) if i < num: print (musical_groups[i]) i += 1
Was meant to print only groups with 3 members...
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:
members = ", ".join(members)
print(members)
3 Answers
Janko Bauer
13,358 PointsHi,
Try an if statement, in the for loop, with: if len in equal or greater than 3. If true run the join, else continue.
But let me know if you need further assist.
Balazs Ferencz
4,993 PointsHi thanks for the help... :)
for members in musical_groups: # comment line # if len(members) == 3: print(members)
This does exactly what the challenge asks for yet the challenge gives me an error saying I'm not joining the lists.
If I put the line to .join the lists where I say #comment line the whole code does not work. Why? Also is my answer wrong or is the challenge funny? As in an offline editor the code works as intended...:)
Janko Bauer
13,358 PointsDid you indent after the if check? that might be a problem.
And take out the print statement. The checker bot does not like calling or print statements in the code. I also struggled with that.
Have the join in the if as you had it. Just remove the print.
Let me know if you need anything else.
Balazs Ferencz
4,993 PointsFigured it out finally thanks for the help, it was a matter of swapping the order of lines...:)
Thanks a lot again...:)
Janko Bauer
13,358 Pointshave fun