how to take index first and last in python in one way
[some_list[0], some_list[-1]]
how to take index first and last in python in one way
[some_list[0], some_list[-1]]
python loop list from last to first
# credit to the Stack Overflow user in the source link
>>> a = ["foo", "bar", "baz"]
>>> for i in reversed(a):
... print(i)
...
baz
bar
foo
# in case you want to keep track of the index
>>> for i, e in reversed(list(enumerate(a))):
... print(i, e)
...
2 baz
1 bar
0 foo
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us