Skip to content

Instantly share code, notes, and snippets.

View emblondel's full-sized avatar

Emmanuel Blondel emblondel

  • Inovasia
  • Les Lilas
View GitHub Profile
@emblondel
emblondel / nested_iterator.py
Created October 13, 2022 07:50
Returns an iterator that returns all key value pairs of a (nested) iterable.
def get_all_key_values(iterable, allow_sub_elements=False):
"""Returns an iterator that returns all key value pairs
of a (nested) iterable. If allow_subdict set to False,
will return only the subvalues, and not the nested dict
or list
Arguments:
- iterable: <list> or <dictionary>
- allow_subdict : boolean