Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to invert a list in python

# Use the reversed function:
xs = [0, 10, 20, 40]
for i in reversed(xs):
  print(i)

# To get a reversed list:
list(reversed(xs))
[40, 20, 10, 0]
 
PREVIOUS NEXT
Tagged: #invert #list #python
ADD COMMENT
Topic
Name
8+8 =