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

Changed Dict(ks,vs) to behave like Dict(zip(ks,vs)) #5419

Merged
merged 1 commit into from
Jan 18, 2014

Conversation

ivarne
Copy link
Member

@ivarne ivarne commented Jan 16, 2014

Currently the lenght of ks is used to deterimine the numer of elements in the dictionary. After this, the shortest of ks and vs is used.

An alternative might be to throw an error if they are not equal length, but I think the same behavior as Dict(zip(ks,vs)), is the most intuitive.

Currently the lenght of ks is used to deterimine the numer of elements
in the dictionary. After this, the shortest of ks and vs is used.

An alternaltive might be to throw an error if they are of equal lenght,
but I think the same behaviour as Dict(zip(ks,vs)), is the most
intuitive.
@toivoh
Copy link
Contributor

toivoh commented Jan 16, 2014

I would vote to throw an error for unequal lengths both here and with zip. Or is anyone actually using that behavior of zip intentionally?

@ivarne
Copy link
Member Author

ivarne commented Jan 16, 2014

The behavior with unequal lengths could be used with infinite iterators, but I have not seen any of those in Julia.

Examples might be a range that never stops counting (just wraps around) or something that just repeats a number, but I am not aware of any uses in Julia.

Dict(zip(keys, repeat(0))) would be a useful idem to create a dictionary with keys initialized to zero.

Hmm... I just realized that Dict does not have a 1 argument constructor for iterables that would be suitable for the zip idiom. Is that a oversight, or is there any reasoning behind?

@ivarne
Copy link
Member Author

ivarne commented Jan 16, 2014

Oops. the last comment is discussed in #4871

@JeffBezanson
Copy link
Member

We might as well just switch to zip, which now runs at full speed for 2 arguments. But, length can serve as a size hint (it was silly of me not to use this in the current constructor), and general iterators might not support length.

JeffBezanson added a commit that referenced this pull request Jan 18, 2014
Changed Dict(ks,vs) to behave like Dict(zip(ks,vs))
@JeffBezanson JeffBezanson merged commit b88653e into JuliaLang:master Jan 18, 2014
@ivarne ivarne deleted the dict-k-v branch February 24, 2014 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants