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

Help! Python, list course, last challenge.

Hi everybody , i can't solve the problem in the last challenge of the lists's course. I know there's a For, in , and a join method involved but i tried some stuff nothing works. Please help.

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:

Hi Alberto, You should loop over the group and in each iteration you should join a group then add in a new list I just put the working example down I hope it helps

Your code here

output =[]

for group in musical_groups: s = ", " s = s.join(group) output.append(s)

print(output)

Tim Oltman
Tim Oltman
7,730 Points

Hi Alberto,

You got the first line right. Now what do you want to do with each group? Remember that .join is a method for strings. For example:

date = ["2020", "June"]
print("-".join(date)) # "2020-June"

3 Answers

Hi Alberto, You should loop over the group and in each iteration you should join a group then add in a new list I just put the working example down I hope it helps

Your code here

output =[]

for group in musical_groups:

       s = ", " 

       s = s.join(group) 

       output.append(s)

print(output)

Thank you very much Sinan and Tim you both were really helpful and I was able to solve the problem!! After I solved it, I did some more research and I was able to find another solution as well. Is anyone able to explain it to me? Here's the code:

For group in musical_groups:
print(", ".join([str(member) for member in group]))

Hi Alberto

Basically This is called list comprehension in python . Instead of using loop an putting in a list , you can just use this syntax in one line . I hope his youtube video can help to better understand.

https://www.youtube.com/watch?v=AhSvKGTh28Q

Thank you very much again Sinan, video very helpful!