Sometimes, while working with python lists we can have a problem in which we need to perform a merge operation on string of lists. This merge is consecutive to convert multiple spaces to one. Lets discuss certain way in which this can be performed.
Method #1 : Using loop
This is brute way in which this task can be performed. In this we find for empty strings using loop and ignore the consecutive strings in making of new list.
The original list is : ['Gfg', '', '', '', 'is', '', '', 'best', ''] List after removal of consecutive empty strings : ['Gfg', '', 'is', '', 'best', '']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Merge Consecutive digits Strings
- Python | Remove empty strings from list of strings
- Python | Ways to merge strings into list
- Python | Merge list of tuple into list by joining the strings
- Python Program to Count number of binary strings without consecutive 1's
- Python | Pair the consecutive character strings in a list
- Python - Consecutive element deletion strings
- Python - Equidistant consecutive characters Strings
- Python | Merge Python key values to list
- How to write an empty function in Python - pass statement?
- numpy.empty() in Python
- Python - Check if a list is empty or not
- Python | Remove empty tuples from a list
- Python | Remove and print every third from list until it becomes empty
- Python | First Non-Empty String in list
- Python program to check if string is empty or not
- Python | Initializing dictionary with empty lists
- Python | Pandas TimedeltaIndex.empty
- Python | Pandas DataFrame.empty
- Python | Remove trailing empty elements from given 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.