def flatten(lst): '''Returns a new list that has the same elements as in lst if we remove all nested lists from within lst.''' returnList = [] for e in lst: if isinstance(e, list): returnList.extend(flatten(e)) else: returnList.append(e) return returnList