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 Python Basics (2015) Python Data Types Specific Index value

What is the problem

Make a new variable, var2, with "e" at index -2. Remember, negative indexes start at the right side of the iterable.

I put this code.

var1 = "hakket"
t = var1[5]
var2 = var1.index('e')

var2 = var1[-2]

Which one is correct?

index.py
var1 = ["x","a","b","c","e","t"]
var1[5]
var2 = var1.index("e")

3 Answers

var1 = [1,3,4,5,6,"t"]

var2 = ["f",2,6,7,"e",9]

The challenge is asking you to create a new list with "e" as the second to last item.

Dhruv Patel
Dhruv Patel
8,287 Points

var1 = list("tttttt")

This is all there is to it. Since we know we want the 5th index to be a letter "t" then we know its length needs to be greater than 6, as indices start at 0. So I just made a list out the of the string with 6 "t"'s. Hope that helps.

Jose Luis Lopez
Jose Luis Lopez
19,179 Points
var1 = "abcdet" 
"t" is at index[5]

var2 = "abcdef" 
if you count backwards, "e" is at negative -2 is all you have to do