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.