10 examples of 'flatten list of tuples python' in Python

Every line of 'flatten list of tuples python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
19def flatten(list_of_lists):
20 """Flatten one level of nesting."""
21 return itertools.chain.from_iterable(list_of_lists)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

59def flatten(listOfLists):
60 return itertools.chain.from_iterable(listOfLists)
183def flatten_list(l: List[List]):
184 return list(itertools.chain.from_iterable(l))
92def flatten(args):
93 if isinstance(args, (list, tuple)):
94 for arg in args:
95 for item in flatten(arg):
96 yield item
97 elif args is not None:
98 yield args
153def _flatten(iterable):
154 for elem in iterable:
155 if isinstance(elem, (tuple, list)):
156 for i in elem:
157 yield i
158 else:
159 yield elem
21def flatten(lst):
22 return list(itertools.chain(*lst))
454def flatten(listOfLists):
455 """
456 Flatten one level of nesting given a list of lists. That is, convert
457 [[1, 2, 3], [4, 5, 6]] to [1, 2, 3, 4, 5, 6].
458
459 :param listOfLists: a list of lists, obviously
460 :return: the flattened list
461 """
462 from itertools import chain
463
464 return list(chain.from_iterable(listOfLists))
47def _flatten(*args):
48 arglist = []
49 for arg in args:
50 if isinstance(arg, (list, tuple, set)):
51 for item in arg:
52 arglist.extend(_flatten(item))
53 else:
54 arglist.append(arg)
55 return arglist
72def flatten(iterable):
73 """Flatten a list of lists by one level so that
74 [1,["abc"], "def",[2, [3]]]
75 becomes
76 [1, "abc", "def", 2, [3]]"""
77 rv = []
78 for item in iterable:
79 if hasattr(item, "__iter__") and not isinstance(item, types.StringTypes):
80 rv.extend(item)
81 else:
82 rv.append(item)
83 return rv
537def flatten(*args):
538 for x in args:
539 if isinstance(x, (list, tuple)):
540 for y in flatten(*x):
541 yield y
542 else:
543 yield x

Related snippets