Ad

Wednesday, December 6, 2017

Reverse a Python List in Place


There are two easy ways to reverse Python in place shown in this beginner Python tutorial. 

l = [1, 5, 6, 2]
l.sort(reverse=True)
l.reverse()
Note .reverse() only reverse the order if there is an order in the first place like timestamp data.

There is also 
sorted(l, reverse=True)
l is just our list variable name. This is not an in place sort. It returns a copy! Remember to update your copy if you have changed or modified the list. 

No comments:

Post a Comment

React UI, UI UX, Reactstrap React Bootstrap

React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid