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!
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
multidimentional musical groups
missing out what text to put in, question is too broad, need better hints
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 musical_groups.join("A" + ", ") print() for musical_groups in "A" + ", ". join
Alex KoumparosPython Development Techdegree Student 36,886 Points
Let's take a look at the instructions and pick out the specific hints for how to approach the problem.
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?
The first couple of sentences just defines some terms for us: group and members. We'll use those definitions in the second half of the question.
The question then says, "loop through each group". That's a hint that you'll want to use a loop. Since we have a collection that we're going to iterate through, we'll want to use a
It then says "output the members". That's a bit ambiguous, but since we're just using a loop construct and not being asked to define a function, we're probably not being asked to
return anything, so let's assume that we're just going to print something on each loop iteration.
It then says we want the output "joined together with a
, comma space as a separator". That's a hint that we'll want to use the
join method for joining together array elements to create a string. Remember that you are calling the
join method on the text you want to use to join the elements together with, and the argument passed to
join is the collection you are joining.
For example, to join
['a', 'b', 'c'] with semicolons you would do the following:
Hopefully that points you in the right direction.
Adam Gataev9,633 Points
Wow!! It looked so difficult but it was easy thanks Alex Koumparos!!