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

Python Introducing Lists Build an Application Multidimensional Musical Groups

Need help with challenge 1

for i in range(len(musical_groups)):
    for j in range(len(musical_groups[i])):
        print(musical_groups[i][j], end=',')

This is my code but getting this error.

FAIL: test_expected_code (__main__.TestLoopAndJoinCode)
Traceback (most recent call last):
  File "", line 32, in test_expected_code
AssertionError: 'join' not found in 'musical_groups = [\n    ["Ad Rock", "MCA", "Mike D."],\n    ["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"],\n    ["Salt", "Peppa", "Spinderella"],\n    ["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"],\n    ["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"],\n    ["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"],\n    ["Run", "DMC", "Jam Master Jay"],\n]\n# Your code here\nfor i in range(len(musical_groups)):\n    for j in range(len(musical_groups[i])):\n        print(musical_groups[i][j], end=\',\')\n    print()' : For each group, you should use the join method on a separator to combine the group members

Ran 1 test in 0.001s

FAILED (failures=1)

3 Answers

Ray Karyshyn
Ray Karyshyn
13,443 Points

Check out the join function:

  1. http://www.pythonforbeginners.com/data-types/python-join-examples)
  2. https://stackoverflow.com/a/1876206
for i in range(len(musical_groups)):  # Loop through each item in 'musical_groups'
    print(", ".join(musical_groups[i]))  # Join the sub-list using the ", " string

Ray can you example this to me

Ray Karyshyn
Ray Karyshyn
13,443 Points

If you have a list:

my_list = ["tic", "tac", "toe"]

You can create a string with a custom selection to place between the items. In this case, I will create the word "tic-tac-toe" using my_list and the join method.

my_string = "-".join(my_list)  # returns "tic-tac-toe"

As you can see, I write the selection I want in between the items ("-"), then a dot, then the method join(), passing the list within the parenthesis.

Thanks Ray. Still cant figure it out. Can you provide the answers?

Myers Carpenter
Myers Carpenter
6,421 Points

Ken Yee We try to help without giving the exact answer here. What is your current attempt at a solution?