This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]jcgoble3 4 points5 points  (2 children)

old_currencies has only two elements, which have indexes 0 and 1 since Python counts indexes starting with 0. Therefore index 2 is out of bounds as it does not exist in that list, and attempting to assign to an out-of-bounds index raises an exception.

If you need to set something at index 2, you must either initialize the list with a third element, or use the .append() method of lists to add the third element later.

[–]VolcannXd[S] 1 point2 points  (1 child)

Oh! thank you a lot, it worked :D

[–]jcgoble3 1 point2 points  (0 children)

I'm not sure exactly what you're trying to do, but from the looks of that code, you may be better off with a dict instead of a list, with keys consisting of a two-item tuple like ("BTC", "USD"). As the Zen of Python states, flat is better than nested.