Sometimes, while working with Python list, we can have a problem in which we need to perform sorting only of alternatively in list. This kind of application can come many times. Let’s discuss certain way in which this task can be performed.
Method : Using
join() + enumerate() + generator expression +
This task can be achieved by using combination of functionalities above. In this, we perform the sort using just %2 elements in String list. The extension of this operation to entire list is performed by generator expression.
The original list : ['cdab', 'gfeh', 'kjil'] The String list after alternate sorting : ['abcd', 'hgfe', 'ijkl']
- Python | Sort each String in String list
- Python | Sort given list of strings by part of string
- Python | List Initialization with alternate 0s and 1s
- Python | Alternate Cycling in list
- Python | Alternate element summation in list
- Python | List consisting of all the alternate elements
- Python | Alternate range slicing in list
- Python | Maximize alternate element List
- Python | Add element at alternate position in list
- Python | Increasing alternate element pattern in list
- Python | Alternate cases in String
- Python | Alternate vowels and consonents in String
- Python | Sort list of list by specified index
- Python | Sort list according to other list order
- Python | Sort the values of first list using second list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.