Flattening a shallow list in Python

Answer

accepted

If you're just looking to iterate over a flattened version of the data structure and don't need an indexable sequence, consider itertools.chain and company.

>>> list_of_menuitems =[['image00','image01'],['image10'],[]]>>>import itertools
>>> chain = itertools.chain(*list_of_menuitems)>>>print(list(chain))['image00','image01','image10']

All python Questions

Ask your interview questions on python

Write Your comment or Questions if you want the answers on python from python Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---