Skip to content
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

add pop!(::Dict) to return a key=>value pair #21947

Merged
merged 1 commit into from
May 19, 2017
Merged

add pop!(::Dict) to return a key=>value pair #21947

merged 1 commit into from
May 19, 2017

Conversation

rfourquet
Copy link
Member

I didn't find a discussion on this method, so I guess it's simply an omission. I propose it because I needed it.

@ararslan
Copy link
Member

Since Dicts aren't ordered, this can return any pair? Seems kinda weird, IMO, since pop! to me typically implies removal from a well-defined position. Out of curiosity, what was your use case for this?

@ararslan ararslan added the collections Data structures holding multiple items, e.g. sets label May 18, 2017
@iamed2
Copy link
Contributor

iamed2 commented May 18, 2017

For comparison, Python has dict.popitem() and dict.pop(key[, default])

@rfourquet
Copy link
Member Author

This is no more weird than pop(::Set) returning any of its elements - and is what happens with normal iteration, where all the elements are visited in a non-specified order. This is useful for example if I want to iterate over all elements of a Set/Dict which can be modified, i.e. new elements are added from within the loop (I use the dict as a stack).

@ararslan
Copy link
Member

Interesting, I didn't realize we supported pop!(::Set) either. I guess this is fine then, especially if it has precedent in other languages.

Copy link
Member

@StefanKarpinski StefanKarpinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ararslan ararslan merged commit 31f798e into master May 19, 2017
@ararslan ararslan deleted the rf/dict-pop branch May 19, 2017 01:52
rfourquet added a commit that referenced this pull request May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants