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 trialmohan Abdul
Courses Plus Student 1,453 Pointslen, 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?
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
Courses Plus Student 1,453 PointsKRIS NIKOLAISEN for example how does len know there were 3 members in ad rock?
mohan Abdul
Courses Plus Student 1,453 PointsKRIS 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
Treehouse Guest TeacherHello, 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
KRIS NIKOLAISEN
54,971 PointsWhen applied to a list len()
returns the number of items in the list. Each group above is a list.
KRIS NIKOLAISEN
54,971 PointsThe 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:
mohan Abdul
Courses Plus Student 1,453 Pointsmohan Abdul
Courses Plus Student 1,453 PointsKRIS NIKOLAISEN, if i execute this could it comes back with groups that 3 band members.
if len(musical_group) == 3:```