Tags
python
Asked 3 years ago
6 Aug 2021
Views 372
Theodora

Theodora posted

how to Print a list in reverse order ?

following is Python list :
 
x=[11,21,31,41,51,61,71,81,91]


how to print a list in reverse order ?
debugger

debugger
answered Aug 6 '21 00:00

below code is do the job , it will print list in reverse

x=[11,21,31,41,51,61,71,81,91]
print(list(reversed(x)))


reversed() function can help to reverse the list
reversed() : Return a reverse iterator object.

so reversed(x) is reversed list_reverseiterator object so iterator object need to convert to list again
so use list() convert iterator object to list , here list([iterable]) will return a mutable sequence list.
Post Answer