Open Marco-Sulla opened 4 years ago
Are #13, #14 and similar all "feature-creep"? i.e. adding extra functions that you think that Python dictionaries should have?
Should frozendict
'just' be a frozen dict-like class with the same API as dict
, or are you writing a frozendict++
? :stuck_out_tongue_winking_eye:
Yes, I think dict
should have a keys_of()
. It's similar to list.index()
and I feel the need of it a couple of times. My hope is that it will be developed also in dict
.
frozendict
is a map-like object. It can't have the same API of dict
, since dict
is mutable. But it have all the API that does not change the object. So the APIs can't be ever equal.
Your observation about feature-creep is good. Software and libraries have the tendency of overdoing. See Netscape for example. And the the KISS and YAGNI principles are always valid.
I suppose the questions we have to answer to ourselves when we want to add another feature to our class / library / app are:
IMHO the answer to these questions, in this case, are yes, inherent, no.
Reopening for implementing it also in the C Extension.
keys_of(value, deep=False)
method should return a generator, that checks infrozendict
values if they are equal tovalue
. 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:
See also #14