grains.utils.flatten_list¶
-
grains.utils.
flatten_list
(nested_list)[source]¶ Merge a list of lists to a single list.
- Parameters
nested_list (list) – List containing other lists.
- Returns
list – Flattened list.
Notes
Only a single level (i.e. list of lists) is handled, see the second example.
Several methods, such as list comprehension, monoid and loops, are proposed in https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists. Here, the list comprehension approach is used.
Examples
>>> nested_list = [['some'], ['items']] >>> flatten_list(nested_list) ['some', 'items'] >>> multiply_nested_list = [[['item'], 'within', 'item']] >>> flatten_list(multiply_nested_list) [['item'], 'within', 'item']