The answer is simply: no.
Questions of the form "does XXX exist" never tend to get answered directly when the answer is no, so I figured I'd put it out there.
Most itertools helpers and builtins operate on generic iterators. map
, filter
, list comprehensions, for
--they all work on iterators, not modifying the original container (if any).
Why aren't there any mutating functions in this category? Because there's no generic, universal way to assign values to containers with respect to their keys and values. For example, basic dict iterators (for x in {}
) iterate over the keys, and assigning to a dict uses the result of the dict as the parameter to []. Lists, on the other hand, iterate over the values, and assignment uses the implicit index. The underlying consistency isn't there to provide generic functions like this, so there's nothing like this in itertools
or in the builtins.
They could provide it as a methods of list
and dict
, but presently they don't. You'll just need to roll your own.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…