+ 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 ,

16th Aug 2019, 6:51 PM
Sami Mestar
Sami Mestar - avatar
6 Answers
+ 12
You can use this: 1. list[::-1] 2. list.reverse() 3. reversed_list = reversed(list)
16th Aug 2019, 6:57 PM
just trying to think
just trying to think - avatar
+ 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.
16th Aug 2019, 7:04 PM
Jigar Wadhwana
Jigar Wadhwana - avatar
+ 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.đŸ€—
17th Aug 2019, 4:14 PM
Gwendolyn Phillips de Ashborough
Gwendolyn Phillips de Ashborough - avatar
+ 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.
16th Aug 2019, 6:52 PM
Brave Tea
Brave Tea - avatar
0
You can also use that A =[7,9,5] Print(f"your reverse is {A[: : -1]}")
17th Aug 2019, 6:35 AM
Akash Pawar
Akash Pawar - avatar
0
list[::-1] is the easiest way and i do it
19th Aug 2019, 5:36 AM
Matthew Li
Matthew Li - avatar