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 alternate numeric and alphabet list
- Python | Sort each String in String list
- Python | Sort given list of strings by part of string
- Python | Reverse Order Sort in String List
- Python - Numeric Sort in Mixed Pair String List
- Python | List Initialization with alternate 0s and 1s
- Python | Alternate Cycling in list
- Python | Add element at alternate position in list
- Python - Repeat Alternate Elements in list
- Python | Multiplying Alternate elements in List
- Python | Alternate range slicing in list
- Python - Alternate Minimum element in list
- Python | Maximize alternate element List
- Python | Alternate element summation in list
- Python | List consisting of all the alternate elements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.