朱莉娅错误:未在词典中定义地图

时间:2018-12-13 05:07:27

标签: dictionary julia

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

hotcell2vocabDict,有没有一种方法可以反转Dict中的键和值?

1 个答案:

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

当然,这是假设您词典中的值是唯一的。