julia> hotcell2vocab = Dict([(cell, i-1+vocab_start)
for (i,cell) in enumerate(hotcell)]);
julia> vocab2hotcell = map(reverse, hotcell2vocab)
ERROR: map is not defined on dictionaries
hotcell2vocab
是Dict
,有没有一种方法可以反转Dict
中的键和值?
答案 0 :(得分:2)
这是您要寻找的吗?
julia> d = Dict(i => i+10 for i in 1:5)
Dict{Int64,Int64} with 5 entries:
4 => 14
2 => 12
3 => 13
5 => 15
1 => 11
julia> d_rev = Dict(b=>a for (a,b) in d)
Dict{Int64,Int64} with 5 entries:
14 => 4
13 => 3
11 => 1
15 => 5
12 => 2
当然,这是假设您词典中的值是唯一的。