El lunes, 7 de noviembre de 2016, 9:18:03 (UTC-5), Steven G. Johnson 
escribió:
>
>
>
> On Monday, November 7, 2016 at 9:02:44 AM UTC-5, Fred wrote:
>>
>> Hi,
>>
>> I have many problems to build arrays with the keys of a dictionary except 
>> for the simple situation :
>>
>> a = [uppercase(key) for key in keys(dict)]    # works fine
>>
>> If I try to select the keys with more complex criteria like :
>>
>> dict = Dict("a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5)
>>
>> a = Array{String}
>>
>
> This is a mistake: you just assigned "a" to an array *type*, not an array 
> *instance*.  It should be a = Array{String}(). 
>
> In Julia 0.5, you can also just do:
>
> [k for k in keys(dict) if dict[k] < 2]
>
>
An alternative syntax is

[k for (k,v) in dict if v < 2]

which iterates over (key, value) pairs in the dictionary.
 

Reply via email to