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 trialMichael Lane
4,408 PointsQuestion about Index workspace session - index of 'cd' in the list
Hi Kenneth. Following through the Index video session with you on the workspace. You put 'abcdef' into the variable 'alpha', and then that into the list alpha_list. When you queried the index of 'cd' you got index 2. When I did it, I got an error - because 'cd' is not an item in the list. The list contents I have for alpha_list are ['a', 'b', 'c', 'd', 'e', 'f'].
What gives?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsGood for you to be following along so closely. It's the best way to sharpen your code reading skills. Kenneth Love keeps you on your toes. Looking closer... his code is correct.
In the video at 2:40, Kenneth has switched back to referencing the variable alpha
when looking for `.index('cd'):
$ python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> alpha = 'abcde'
>>> alpha.index('a')
0
>>> 'abcabc'.index('a')
0
>>> alpha_list = list(alpha)
>>> alpha_list.index('b')
1
>>> alpha.index('cd') # <-- referencing alpha not alpha_list
2
>>>
Michael Lane
4,408 PointsMichael Lane
4,408 PointsThanks Chris. I figured I was doing something like that and went looking for it - but debugging late at night often leads to simple and avoidable errors. Cheers.