Here is a relatively simple recursive version which will flatten any depth of list
l = [35,53,[525,6743],64,63,[743,754,757]]
def flatten(xs):
result = []
if isinstance(xs, (list, tuple)):
for x in xs:
result.extend(flatten(x))
else:
result.append(xs)
return result
print flatten(l)
Related Contents:
- How to make a flat list out of a list of lists?
- Flatten an irregular list of lists
- How do I make a flat list out of a list of lists?
- Flatten an irregular (arbitrarily nested) list of lists
- How to flatten a tuple in python
- How do I check if a list is empty?
- What are the advantages of NumPy over regular Python lists?
- How do I initialize a dictionary of empty lists in Python?
- Get unique values from a list in python [duplicate]
- Why can’t I use a list as a dict key in python?
- Extract first item of each sublist
- Remove duplicate dict in list in Python
- Python: Finding differences between elements of a list
- Why does Python skip elements when I modify a list while iterating over it?
- Negative list index? [duplicate]
- Finding the average of a list
- How to read a text file into a list or an array with Python
- Python recursion with list returns None [duplicate]
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Why can tuples contain mutable items?
- How do I check if there are duplicates in a flat list?
- Why is [] faster than list()?
- How to perform element-wise multiplication of two lists?
- Calculating arithmetic mean (one type of average) in Python [duplicate]
- How to group a list of tuples/objects by similar index/attribute in python?
- Check list of words in another string [duplicate]
- Looping over a list in Python [closed]
- How can I generate a list of consecutive numbers?
- Why does appending to one list also append to all other lists in my list of lists? [duplicate]
- Finding elements not in a list
- Python 3 replacement for deprecated compiler.ast flatten function
- How do I split a string into a list?
- merging Python dictionaries
- Interleaving Lists in Python [duplicate]
- How do I convert a list into a string with spaces in Python?
- Remove dictionary from list
- How to compare a list of lists/sets in python?
- Is it possible to get a list of keywords in Python?
- Convert list into a dictionary [duplicate]
- Modifying a list while iterating over it – why not? [duplicate]
- Python: filter list of list with another list
- How to convert list of tuples to multiple lists?
- Identify duplicate values in a list in Python
- Size of a Python list in memory
- Turn Pandas Multi-Index into column
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Find starting and ending indices of sublist in list
- Converting a string that represents a list, into an actual list object [duplicate]
- Converting string to tuple without splitting characters
- Column of lists, convert list to string as a new column