Skip to content

[FEATURE] keys_of() method #13

@Marco-Sulla

Description

@Marco-Sulla

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort: MediumHow to waste a beautiful weekendNeeds: DocImprovements or additions to documentationNeeds: TestHey, it compiles! Ship it!Priority: LowNot a big problem...Type: EnhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions