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 trialSam Morpeth
8,756 PointsStuck on challenge 2 of the multidimensional list challenge.
I'm really struggling to see why anything other than trios are being picked up by the code below:
if len(", ".join(group)) == 3:
print(", ".join(group))
The challenge wants the code to run through a multidimensional list and only print groups which contain 3 members in them. It seems to to pick up The Beatles and print it. I have no idea why. Any body got any ideas as to why this might be happening?
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 group in musical_groups:
print(", ".join(group))
if len(", ".join(group)) == 3:
print(", ".join(group))
6 Answers
Ernestas Petruoka
1,856 PointsSorry my bad I hadn't opened challenge for myself last time and didn't sow that it requires join list. So basically code will stay same as I said just need change print(group) into print(', '.join(group)):
for group in musical_groups:
if len(group) == 3:
print(', '.join(group))
Hope this will work :) BTW Sorry if I made some english mistakes because I still learning english.
Anthony Giordano
1,783 Pointsfor group in musical_groups:
print(", ".join(group))
break
for tri in musical_groups:
if len(tri) == 3:
print(", ".join(tri))
Anthony Giordano
1,783 PointsThe break seemed to help with it separating from the first part of the test.
Sam Morpeth
8,756 PointsThanks for getting back to me! According to the challenge you do still need to use the .join() format. It says in the instructions "Now I'd like to see only groups that are trios, you know 3 members.
So can you please only print out the trios? It should still use the joined string format from task 1."
My code seems to run through the list, but it doesn't only print the trios and I really don't understand why.
The code you suggested didn't seem to work either. It said "Assertion error join expected" or something similar.
I also don't understand where this was covered in the course. I don't remember learning how to do this in any of the videos and I've watched of the videos several times in an effort to understand the content.
Sam Morpeth
8,756 PointsYeah, that worked. Thanks a lot! I watched a couple of the videos back, and I'm in the process of doing that now too, just to make sure I get the concepts explained in the videos. Lists are causing me all sorts of problems.
Lynn Collins
10,080 PointsSmh...this seems to be excellent therapy for my ADHD!
Ernestas Petruoka
1,856 PointsFirst of all your if function need to be inside your for loop. Second mistake is that you don't need use join() method in this challange.
#So change your code
for group in musical_groups:
print(", ".join(group))
if len(", ".join(group)) == 3:
print(", ".join(group))
# Into:
for group in musical_groups:
if len(group) == 3:
print(group)
# That should work