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 trialmendelbakaleynik
1,009 PointsQuestion regarding... well.. stuff.
I'm a little confused by what Kenneth wrote at around 2:30. He had so far written
>>> alpha_list = list(alpha)
>>> alpha_list.index('b')
1
>>> alpha.index('d')
3
>>> 'abcabc'.index('a')
0
>>> alpha_list = list(alpha)
>>> alpha_list.index('b')
1
I was confused by the last two lines. particularly this one,
>>> alpha_list = list(alpha)
I thought he had already defined "alpha" earlier on? What is he doing now, and why is the value for 'b' 1? If he changed the definition for 'alpha' then there is no letter 'b' anywhere.
I'm missing something obvious, but thanks anyway.
3 Answers
Carlos Federico Puebla Larregle
21,074 PointsYou have to see it like this:
1) We have a variable called "alpha" and it holds a String
alpha = 'abcde'
this one is a string: 'abcde'
2) Then later on the video he creates a new variable called "alpha_list" that is going to hold the "list" version of the string placed in the variable "alpha".
alpha_list = list(alpha)
this one is a list: ['a', 'b', 'c', 'd', 'e']
I hope that helps a little bit.
mendelbakaleynik
1,009 PointsActually, I spent some more time banging my head against a wall and I solved this answer right as you posted it. But thanks so much anyway! I'm glad to know I have support.
James Brazil
390 Pointsanyone still having trouble
'''
creating the varible alpha
>>>alpha="abcde"
index for the variable alpha
>>>alpha.index("a")
0
creating a new variable making a list of the word "alpha"
>>>alpha_list=list(alpha)
what list.alpha looks like
>>>print(alpha_list)
{"a", "b", "c", "d", "e"]
so when you put alpha_list.index("b") python finds the b from the list of alpha that you created
'''