+ 1
Hi , how can i reverse the items in a liste ? On python
For exmple i have [7,9,5] , and i wont to have [5,9,7] , using a method or something ,
6 Antworten
+ 12
You can use this:
1. list[::-1]
2. list.reverse()
3. reversed_list = reversed(list)
+ 4
Reversing elements in list can be there done in various ways .One of the easiest way of reversing elements in list is by "Slicing Technique"
Example:
num=[7,9,5]
print(num[::-1])
Hope this helps.
+ 3
Every list in Python has a built-in reverse() method you can call to reverse the contents of the list object in-place. Reversing the list in-place means won't create a new list and copy the existing elements to it in reverse order. Instead, it directly modifies the original list object.🤗
+ 1
google: reverse() python
it is quite easy to do so
https://code.sololearn.com/cWGyRXm9rC8i/?ref=app
take a look at the code because it also explains the difference in usage.
0
You can also use that
A =[7,9,5]
Print(f"your reverse is {A[: : -1]}")
0
list[::-1] is the easiest way and i do it