Similar questions were asked before, but solutions for them do not work for my use case (for example, Creating a flat list from a list of lists in Python and Smoothing a small list in Python . I have a list of strings and lists where the built-in list can also contain strings and lists I want to turn this into a simple list of strings without splitting the strings into a list of characters.
import itertools list_of_menuitems = ['image10', ['image00', 'image01'], ['image02', ['image03', 'image04']]] chain = itertools.chain(*list_of_menuitems)
Summary list:
['i', 'm', 'a', 'g', 'e', '1', '0', 'image00', 'image01', 'image02', ['image03', 'image04']]
Expected Result:
['image10', 'image00', 'image01', 'image02', 'image03', 'image04']
What is the best (Pythonic) way to do this?
python list
Ian gow
source share