macpie.itertools.overlay#
- macpie.itertools.overlay(bottom, top, predicate=None, constrain_to_top=False, fillvalue=None)#
Overlay elements from
top
overbottom
. Ifpredicate
is specified, only overlay elements from top over elements inbottom
for whichpredicate
(for bottom) is true.An iterator of the result is returned.
>>> bottom = [1, 2, None, 4, None, 6, 7] >>> top = [0, 0, 3, 0, 5, 0, 0] >>> result = overlay(bottom, top, lambda x: x is None) >>> list(result) [1, 2, 3, 4, 5, 6, 7]
- Parameters:
- bottomiterable
if predicate is true for an element, overlay corresponding element from top (i.e. replace the element with the one from top)
- topiterable
iterable to copy values from
- predicateBoolean-valued function
to test each element of bottom, overlaying parallel values from top if true. If ‘None’ (default), do not overlay any values from top.
- constrain_to_topbool, optional, default: False
constrain values to top. if true and top is shorter than bottom, truncate bottom to match length of top; if top is longer than bottom, fill extra elements with fillvalue
- fillvalueoptional, default: None
value to fill extra items with