Sometimes, while working with Python list, we can have a problem in which we need to add elements in list alternatively i.e at even positions and reorder the list accordingly. This has a potential application in many domains such as day-day programming and competitive programming. Let’s discuss certain way in which this problem can be solved.
Method : Using
join() + list()
This method can be used to solve this problem in one line. In this, we just join all the elements alternatively with target element and then convert back to list using
The original list is : ['a', 'b', 'c', 'd', 'e', 'f'] List after alternate addition : ['a', '#', 'b', '#', 'c', '#', 'd', '#', 'e', '#', 'f']
- Python | Maximize alternate element List
- Python | Alternate element summation in list
- Python | Increasing alternate element pattern in list
- Python | Shift last element to first position in list
- Python | Maximum and minimum element's position in a list
- Python | Alternate Cycling in list
- Python | List Initialization with alternate 0s and 1s
- Python | Alternate Sort in String list
- Python | Alternate range slicing in list
- Python | List consisting of all the alternate elements
- Python | Position Summation in List of Tuples
- Python | Selective Merge list every Nth position
- Python | Find frequency of given character at every position in list of lists
- Python | Subtract two list elements if element in first list is greater
- Python | Replace elements in second list with index of same element in first 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 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.