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

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

Having trouble here's my code

var_two [ 'e' ] = -2

6 Answers

var_one = ['a','b','c','d','e', 't']

var_two[-2] = ['e']

Patrick Madden
Patrick Madden
1,632 Points

The challenge is asking you to create a new variable called "var_two". This variable is going to be equal to a list, string, dictionary, tuple ext... anything with an 'e' at the index of -2. Think of it like this...

'''      0     1     2     3     4     5
      _____________________________________
      |  a  |  p  |  p  |  l  |  e  |  s  |
      -------------------------------------
        -6    -5    -4    -3    -2    -1
'''

As long as you have an 'e' in that spot you would be completing the challenge by using var_two = 'apples' because 'e' is at an index of -2.

var_one = ['a','b','c','d','e', 't']

var_two[-2] = ['a','p','p','l','e']

not working

Patrick Madden
Patrick Madden
1,632 Points

"Ramon Villarreal-Leal 15 minutes ago var_one = ['a','b','c','d','e', 't']

var_two[-2] = ['a','p','p','l','e']

not working"

Ramon, the way you have the variable declared, the 'e' is in index -1. Remember, when going backwards through an iterable it starts at -1 then -2, -3, and so on. if you were to add one more string at the end of your list like 's' to make it

['a', 'p', 'p', 'l', 'e', 's']

it will pass because then the 'e' is at -2 because the 's' will be at -1.

I cannot figure it out lmao

var_one = ['a','b','c','d','e', 't']

[-2] = ['a', 'e'] = var_two

Not sure

Thanks man you helped a lot

Patrick Madden
Patrick Madden
1,632 Points

Hey Ramon,

It's simply asking you to create another variable much like you did in the first task. For instance...

var_two = 'index'

It's simply a string with an 'e' in index -2 (second from end)