Answers for "reverse in python"

55

reverse list python

>>> the_list = [1,2,3]
>>> reversed_list = the_list.reverse()
>>> list(reversed_list)
[3,2,1]

OR

>>> the_list = [1,2,3]
>>> the_list[::-1]
[3,2,1]
Posted by: Guest on February-11-2020
7

how to flip a list backwards in python

myList = [0,1,2,3,4,5]
myList.reverse()
print(myList)
#OR
print(myList[::-1])
Posted by: Guest on February-22-2020
2

inverted for python

for i in reversed(range(5)):
    print(i)
Posted by: Guest on September-13-2020
8

reverse list python

list=[1,2,3]
list[::-1]
Posted by: Guest on May-08-2020
1

reverse a list in python

a = ['a', 'b', '4', '5', 'd'] #reverse the List
print(list(reversed(a)))
Posted by: Guest on December-21-2020
7

python reverse

my_list = [1, 2, 3]
my_list.reverse()           # my_list is modified
print(my_list)              # '[3, 2, 1]'
my_revert = my_list[::-1]   # my_list stays [3, 2, 1]
print(my_revert)            # '[1, 2, 3]'
# Item by item reverse with range(<start>, <end>, <step>)
for i in range(len(my_list), 0, -1):		# my_list is [3, 2, 1]
    print(my_list[i-1])		# '1' '2' '3'
for i in reversed(range(len(my_list))):
    print(my_list[i])       # '1' '2' '3'
Posted by: Guest on May-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language