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

mohan Abdul
PLUS
mohan Abdul
Courses Plus Student 1,453 Points

len, is normally length of word or string or even characters. How does len know that certain words contain 3 band membe

len, is normally length of word or string or even characters. How does len know that certain words contain 3 band members?

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"],
]
# Your code here
mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

KRIS NIKOLAISEN, if i execute this could it comes back with groups that 3 band members.

if len(musical_group) == 3:```
mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

KRIS NIKOLAISEN for example how does len know there were 3 members in ad rock?

mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

KRIS NIKOLAISEN, yes thanks for your speedy reply. len is used to check the length of a word or string what len doesn't do is go back into history to see who invented the word. The same for band members len doesnt go into the history of the band to find out how many members there were. So how does it do it in this instance? unless these band names were assigned values in python?

Justin Horner
Justin Horner
Treehouse Guest Teacher

Hello, Mohan

We're you able to pass the challenge with the answers provided by KRIS NIKOLAISEN? If not, please let us know how we can help further.

Take care

2 Answers

When applied to a list len() returns the number of items in the list. Each group above is a list.

The challenge uses a list of lists. So if you loop through the list with:

for musical_group in musical_groups:
  print(musical_group)

you would output:

['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 condition for checking for three members in musical_group is correct

if len(musical_group) == 3:

For the first item this is the same as:

if len(['Ad Rock', 'MCA', 'Mike D.']) == 3: