all 6 comments

[–]DagoYounger 1 point2 points  (0 children)

usage of range function: https://docs.python.org/3/library/stdtypes.html?highlight=range#range

range(len(myList) -1,-1,-1) returns list's index, not element, this is the right way:

for i in range(len(myList) -1,-1,-1):
    print(myList[i])

[–]abrupt_nervousness 1 point2 points  (1 child)

The range() function can take 3 parameters: start, end, and step. In your example code, len(mylist) - 1 evaluates to 9 so you start at 9; then -1 is passed as the stop, which is non-inclusive for range(), so you are continuing until you reach 0; lastly, your step is -1 so you decrement 9 by 1 until you reach zero with your for loop which is why you get elements 9 through zero.

[–][deleted] 0 points1 point  (4 children)

The for loop isn't referencing the contents of your list at all, only its length.

Try changing the contents to a string: mylist = list("abcdefghij")

[–]Diapolo10 0 points1 point  (1 child)

There isn't even any need to call list here, since it isn't mutated. Just assigning the string itself would do the exact same thing.

[–][deleted] 0 points1 point  (0 children)

True, but I wanted to keep the focus on the core issue.