MCPcopy
hub / github.com/networkx/networkx / flatten

Function flatten

networkx/utils/misc.py:46–57  ·  view source on GitHub ↗

Return flattened version of (possibly nested) iterable object.

(obj, result=None)

Source from the content-addressed store, hash-verified

44
45
46def flatten(obj, result=None):
47 """Return flattened version of (possibly nested) iterable object."""
48 if not isinstance(obj, Iterable | Sized) or isinstance(obj, str):
49 return obj
50 if result is None:
51 result = []
52 for item in obj:
53 if not isinstance(item, Iterable | Sized) or isinstance(item, str):
54 result.append(item)
55 else:
56 flatten(item, result)
57 return tuple(result)
58
59
60def make_list_of_ints(sequence):

Callers 1

test_flattenFunction · 0.90

Calls 1

appendMethod · 0.80

Tested by 1

test_flattenFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…