Skip to content

[feature] get map keys by values #23

@RiedleroD

Description

@RiedleroD

builtin function that does the equivalent of this (python) function:

def get_keys_by_value(arr: dict, value) -> list:
    return [k for k, v in arr.items() if v == value]

# defining dictionary
arr = {"a": 2, "b": 2, "c": 4, "e": 2}
# getting keys that point to value 2
twos = get_keys_by_value(arr, 2)
# twos now equals ["a", "b", "e"]

this should probably be type checked, i.e. you can't look for a string in a dictionary that has integers. Also this should probably not be supported for doubles, since there's all sorts of silly bs going on there (e.g. -0 and +0 are not the same value). at the very least it should issue a compile-time warning.

i.e., given arr: Map<mK, mV> and value: V, the following should hold true: mV == V && V != double

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requeststdlibThis issue is about the standard library

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions