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

Derek Graham Chema
Derek Graham Chema
845 Points

I find this problem to be super confusing, any help?

So i found the solution for this problem on the web, but my brain can't catch why this actually works, so with the for loop you are going through each step of the list which contents another list, is this a nested way to make the loop?

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:
    group = ", ".join(group)
    print(group)

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Data Analysis Techdegree Graduate 45,972 Points

Hey Derek Graham Chema ! :wave:

Yes, so here we have a list of lists of strings.

So in our for group in musical_groups: loop, we're iterating over each list of strings.

We're then using the .join() method on each of those lists of strings which will take all of those strings inside and combine them into one long string, separated by the ", " that you provided.

So for example

["Ad Rock", "MCA", "Mike D."]

should turn into

"Ad Rock, MCA, Mike D."