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

Ed Basquill
Ed Basquill
3,984 Points

Stuck and can’t see my syntax error For group in musical_groups Print(“, “.join(group))

Last challenge in python lists

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 group in musical_groups
  print(group)
Kaisma Penn-Titley
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kaisma Penn-Titley
PHP Development Techdegree Graduate 20,208 Points

Hey Ed, I spent some time on this challenge too and ended up placing my code in an online python REPL testing multiple solutions. Ultimately, the following worked for me and passed the quiz:

group_number = 1
for groups in musical_groups:
#  if len(groups) == 3: add this to print groups with 3 members
    print("Group: #{}".format(group_number), ", ".join(groups))
    group_number += 1

For the print statement, I added text before the join statement to print out which group I was on.

OUTPUT:
'Group: #1', 'Ad Rock, MCA, Mike D.'
'Group: #2', 'John Lennon, Paul McCartney, Ringo Starr, George Harrison'
'Group: #3', 'Salt, Peppa, Spinderella'
'Group: #4', 'Rivers Cuomo, Patrick Wilson, Brian Bell, ScottShriner'
'Group: #5', 'Chuck D., Flavor Flav, Professor Griff, Khari Winn, DJ Lord'
'Group: #6', 'Axl Rose, Slash, Duff McKagan, Steven Adler'
'Group: #7', 'Run, DMC, Jam Master Jay'

2 Answers

Steven Parker
Steven Parker
231,248 Points

Kaisma's solution is interesting, but you don't need to add the group number to pass the challenge. In fact, for most challenges it's not a good idea to do anything the instructions don't ask for, because it can confuse the validation.

Anyway, your syntax error was just leaving off the colon (:) at the end of the "for" line. But even after fixing that, you'll still need more code to handle the instruction that asks you to "output the members joined together with a ", " comma space as a separator". The word "joined" is a clue there, and the "join" function is perfect for doing this job.

Kaisma Penn-Titley
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kaisma Penn-Titley
PHP Development Techdegree Graduate 20,208 Points

Hi Steven, thank you for your comment. I'm aware that the additional formatting is not needed. However, it made the output more sensible and was able to pass the validation without any challenges.

Steven Parker
Steven Parker
231,248 Points

This particular challenge allows it. But be aware that doing extra things can cause false "fail" results on many of the other challenges. Happy coding!