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 Introducing Lists Build an Application Multidimensional Musical Groups

jemazar
jemazar
3,258 Points

AssertionError in Challenge group 2/2 python

When i run my code on the workspace i get the output i want. When in challenge mode i get a pass on the first test and a fail on the second. Im really clueless what todo here.

groups.py
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"],
]
for members in musical_groups:
    string = ', '.join(members)       

for members in musical_groups:
    if len(members) == 3:
      print(members)        

try:

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

1 Answer

Steven Parker
Steven Parker
229,744 Points

Here's a couple of hints:

  • you'll need only one loop, in task 2 you will add to the task 1 loop
  • in task 2 you will still print the same joined list, only now it will be controlled by an "if" statement
jemazar
jemazar
3,258 Points

I tried to improve it with the clues you gave me Steven Parker, Only 1 loop and the if statement. I passs the first test , fail the second.

for member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)

jemazar
jemazar
3,258 Points

for member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)

Steven Parker
Steven Parker
229,744 Points

Without Markdown formatting it's hard to tell exactly what's happening here. But it doesn't look like the result of the "join" is being saved or printed.

jemazar
jemazar
3,258 Points

Still no pass on 2nd test

for member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)

OUTPUT ['Ad Rock', 'MCA', 'Mike D.'] ['Salt', 'Peppa', 'Spinderella'] ['Run', 'DMC', 'Jam Master Jay']

AssertionError: 'Ad Rock, MCA, Mike D.' not found in "['Ad Rock', 'MCA', 'Mike D.']\n['Salt', 'Peppa', 'Spinderella']\n['Run', 'DMC', 'Jam Master Jay']" : Hmmm...I'm not getting the output I expected.

Steven Parker
Steven Parker
229,744 Points

Please use this link to learn how to use Markdown formatting to show your code (as I have done below).

But that "join" still isn't being used to help with the printout. You might move it inside the "print":

        print((', ').join(member))