This is probably silly and basic but how do I get the list edcba
When I try:
import string
letters = string.ascii_lowercase
letters[4:0:-1]
'edcb'
This somehow makes sense since the index is [4,3,2,1]. However, using -1
results in the following:
letters[4:-1:-1]
''
I know I could just do "".join(reversed(letters[:5]))
or use list comprehension but I am curious on how to do it with negative steps.