Thanks @Tomas 
This is a pretty cool solution. I just figured another one out that does 
not involve inverting the order in the tupels. 
I was pleasantly surprised to discover the Julia's list comprehension makes 
it possible to construct dictionaries. 

Here is it. 

julia> t = (("a", 1), ("b", 2))
(("a",1),("b",2))
julia> [a=>b for (a,b) in t]
{'a'=>1,'b'=>2}



On Monday, May 26, 2014 1:37:12 PM UTC+3, Tomas Lycken wrote:
>
> The easiest way I could find was requires you to invert the order of your 
> tuples. But it turns out in an even more logical way, IMO:
>
> julia> t = (("a", 1), ("b", 2))
> (("a",1),("b",2))
> julia> Dict(zip(t...)...)
> ["b"=>2,"a"=>1]
>
> zip <http://docs.julialang.org/en/latest/stdlib/base/#Base.zip> is one of 
> my favourite functions, and it should be a familiar concept coming from 
> python.
>
> // T
> On Monday, May 26, 2014 11:34:55 AM UTC+2, Mohammed El-Beltagy wrote:
>>
>> In python I could easily generate a dictionary from a list of tuples 
>>
>> For example
>>
>> >>> t = ((1, 'a'),(2, 'b'))
>> >>> dict((y, x) for x, y in t)
>> {'a': 1, 'b': 2}
>>
>>
>> Is is possible to do something similar in Julia?
>>
>> I tried the map function but it gave me errors
>> julia> Dict(map(k->(k[2],k[1]),t))
>>
>> no method Dict{K,V}(Array{Any,1},)
>> at In[100]:1
>>
>>
>>
>>

Reply via email to