Welcome to the Treehouse Community
Looking to learn something new?
Michael Cook5,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
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