hbutils.collection.structural

Overview:

Structural operations.

sq_flatten

hbutils.collection.structural.sq_flatten(s)[source]
Overview:

Sequence flatten.

Arguments:
  • s: The given sequence.

Returns:
  • flatted: Flatted sequence.

Examples::
>>> from hbutils.collection import sq_flatten
>>> sq_flatten([1, 2, [3, 4], [5, [6, 7], (8, 9, 10)], 11])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

nested_walk

hbutils.collection.structural.nested_walk(s) → Iterator[Tuple[Tuple[Union[int, str], ], object]][source]
Overview:

Walk for nested structure.

Arguments:
  • s: Given structure.

Returns:
  • walk_iter (Iterator[Tuple[Tuple[Union[int, str], ...], object]]): Iterator of the walk result.

Examples::
>>> from hbutils.collection import nested_walk
>>> for p, v in nested_walk({'a': 1, 'b': ['c', 'd', {'x': (3, 4), 'y': 'f'}]}):
...     print(p, v)
...
('a',) 1
('b', 0) c
('b', 1) d
('b', 2, 'x', 0) 3
('b', 2, 'x', 1) 4
('b', 2, 'y') f

nested_flatten

hbutils.collection.structural.nested_flatten(s) → List[Tuple[Tuple[Union[int, str], ], object]][source]
Overview:

Flatten for nested structure.

Arguments:
  • s: Given structure.

Returns:
  • flatted (List[Tuple[Tuple[Union[int, str], ...], object]]): List of the flatted result.

Examples::
>>> from hbutils.collection import nested_flatten
>>> print(nested_flatten({'a': 1, 'b': ['c', 'd', {'x': (3, 4), 'y': 'f'}]}))
[(('a',), 1), (('b', 0), 'c'), (('b', 1), 'd'), (('b', 2, 'x', 0), 3), (('b', 2, 'x', 1), 4), (('b', 2, 'y'), 'f')]