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

Comprehension of Dict values #1043

Closed
dmbates opened this issue Jul 12, 2012 · 3 comments
Closed

Comprehension of Dict values #1043

dmbates opened this issue Jul 12, 2012 · 3 comments

Comments

@dmbates
Copy link
Member

dmbates commented Jul 12, 2012

The value of a key from a Dict object has the expected type

julia> d = Dict{Int, Bool}()
Dict()

julia> for i in 1:5 d[i] = true end

julia> typeof(d[1])
Bool

but a comprehension of those values is always an Any Array

julia> [d[k] for k in keys(d)]
5-element Any Array:
 true
 true
 true
 true
 true

Is there a way to create a comprehension like the above producing a Bool Array?

@nolta
Copy link
Member

nolta commented Jul 12, 2012

julia> [d[k]::Bool for k in keys(d)]

@dmbates
Copy link
Member Author

dmbates commented Jul 12, 2012

Thanks, Mike. The reason for my posing this as an issue is because it seems to me that getting the correct type, rather than Any, should be automatic.

(Earlier I wrote Nick instead of Mike forgetting that the reason the name Nick Nolta sounded familiar is because he is an actor.)

@JeffBezanson
Copy link
Member

Note: #524 is still a problem here.

HarlanH pushed a commit to HarlanH/julia that referenced this issue Jul 18, 2012
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

No branches or pull requests

3 participants