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
>
>
>
>