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 | Reverse Order Sort in String List
- Python | Sort given list of strings by part of string
- Python - Numeric Sort in Mixed Pair String List
- Python | Alternate Cycling in list
- Python | List Initialization with alternate 0s and 1s
- Python | Maximize alternate element List
- Python | Alternate range slicing in list
- Python - Alternate Minimum element in list
- Python | Add element at alternate position in list
- Python | List consisting of all the alternate elements
- Python - Repeat Alternate Elements in list
- Python | Alternate element summation in list
- Python | Multiplying Alternate elements in List
- Python | Increasing alternate element pattern in list
- Python | Alternate cases in String
- Python | Alternate vowels and consonents in String
- Python - Convert Alternate String Character to Integer
- Python - Sort dictionaries list by Key's Value list index
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.