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 trialRamon Villarreal-Leal
4,764 PointsMake 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
6 Answers
Ramon Villarreal-Leal
4,764 Pointsvar_one = ['a','b','c','d','e', 't']
var_two[-2] = ['e']
Patrick Madden
1,632 PointsThe 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.
Ramon Villarreal-Leal
4,764 Pointsvar_one = ['a','b','c','d','e', 't']
var_two[-2] = ['a','p','p','l','e']
not working
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.
Ramon Villarreal-Leal
4,764 PointsI cannot figure it out lmao
Ramon Villarreal-Leal
4,764 Pointsvar_one = ['a','b','c','d','e', 't']
[-2] = ['a', 'e'] = var_two
Ramon Villarreal-Leal
4,764 PointsNot sure
Ramon Villarreal-Leal
4,764 PointsThanks man you helped a lot
Patrick Madden
1,632 PointsHey 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)
Ramon Villarreal-Leal
4,764 PointsRamon Villarreal-Leal
4,764 Pointsvar_two [ 'e' ] = -2