-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make keys(dict) and values(dict) more useful #20678
Comments
Mutating # keys(d)[i] = k
d[k] = pop!(d, collect(d)[i].first)
# values(d)[i] = v
d[collect(d)[i].first] = v Moreover, if dictionaries are ordered, then writing code like |
Many moons ago I had a PR for a |
Dup of #10092 (almost exactly 2 years later!) ? |
I would often want to call also |
Wouldn't you want |
Like I said in your PR, I would prefer the predicability of getting an array out. If I wish a |
We probably don't need both of these open. Closing in favor of #10092. |
Currently the very common operation of iterating a Dict's keys in sorted order requires writing the overly verbose
sort!(collect(keys(d)))
. This could be abbreviated tosort(keys(d))
by adding asort
method forKeyIterator
, but do we manually add methods for all relevant functions in Base? What about user-defined functions that make sense for general collection-like types? At some point (IIRC) I proposed makingKeyIterator
andValueIterator
subtypes ofAbstractVector
, which would make many things "just work". The trouble is that indexing is O(n); however, I believe that something like @JeffBezanson's ordered dict experiment could make indexing O(1).The text was updated successfully, but these errors were encountered: