Tags
python
Asked 3 years ago
6 Aug 2021
Views 268
Mikel

Mikel posted

How can I reverse a list in Python?


x=['a','b','31','4','e','f']
print(x)

i want to reverse the list in Python
How can I reverse a list in Python?
debugger

debugger
answered Aug 8 '21 00:00

using the reversed function to reverse the list

reversed(seq)
Return a reverse iterator. seq must be an object


x=['a','b','31','4','e','f']
print(list(reversed(x)))


reversed(x) returns list_reverseiterator object so need to convert to list again by list() function

above code have print reverse the list
Post Answer