-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Effort: MediumHow to waste a beautiful weekendHow to waste a beautiful weekendNeeds: DocImprovements or additions to documentationImprovements or additions to documentationNeeds: TestHey, it compiles! Ship it!Hey, it compiles! Ship it!Priority: LowNot a big problem...Not a big problem...Type: EnhancementNew feature or requestNew feature or request
Description
keys_of(value, deep=False) method should return a generator, that checks in frozendict values if they are equal to value. If yes, the keys are yielded.
If deep=True, value does not match the current value and it's a iterable, that is not an iterator-like or a set-like, the function will search recursively for the value in the iterable and any sub-iterable. If the iterable is a sequence, the indexes of the value is yielded. If it's a map-like, the keys are yielded.
Example:
fd = frozendict({1: 2, 7:2, 2: {5: 2, 7: 2, 0: [2, 1]}, 3: [0, 4, 2, 1, 2]})
tuple(fd.keys_of(2))
# (1, 7)
for x in fd.keys_of(2, deep=True)):
print(tuple(x))
# (1, )
# (7, )
# (2, 5)
# (2, 7)
# (2, 0, 0)
# (3, 2)
# (3, 4)See also #14
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Effort: MediumHow to waste a beautiful weekendHow to waste a beautiful weekendNeeds: DocImprovements or additions to documentationImprovements or additions to documentationNeeds: TestHey, it compiles! Ship it!Hey, it compiles! Ship it!Priority: LowNot a big problem...Not a big problem...Type: EnhancementNew feature or requestNew feature or request