Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Build an Application Multidimensional Musical Groups

Michael Cook
Michael Cook
5,864 Points

(Python) Multidimensional Musical Groups, not sure what the code challenge wants me to do.

Hi, sorry that I have to come back here so quickly, but just like the title says, I'm not sure what this question is exactly asking me.

"Here is a multi-dimensional list of musical groups. The first dimension is group, the second is group members. Can you loop through each group and output the members joined together with a ", " comma space as a separator, please?"

I understand how multi-dimensional lists work, its fairly simple, just lists inside lists, and you can call into a list of a list etc etc.

In the last lesson we went through loops and how to set up certain commands with inputs, which was really cool, but nothing from there rings a bell on what I should do here.

Is it asking me to list all of the members of each group in one GIANT string? Separated by ", "? I'm not exactly sure how to get a loop to do that. I know how to get a 'for' loop to print each item separately, but the question says to join them all with a comma, so it doesn't seem like it wants me to do that.

Again, really sorry to have to come back to the forums asking for help. Any help is greatly appreciated!

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

2 Answers

You are over-thinking things the question basically wants you to take the list and return a string representation of that list separated by "," and the quickest way to do this would be to use the join method

<how the iterable should be joined>.join(iterable)

Now since the join method can be used to separate the list into a string all that left is passing the right list to it... The question says "Can you loop through each group and output the members joined together" which means they want you to iterate over the first list(first dimension) before you can iterate again the second list so your code should look something like:

for group in musical_groups:
    print(', '.join(group))

if you were iterating over one list you could have just used

', '.join(musical_groups)
Michael Cook
Michael Cook
5,864 Points

I can't believe I forgot about that, thank you so much!