dongwuzun4630 2018-09-30 20:49
浏览 55

比较Golang中的两张地图

I have two Maps:

First one:

map[11:manufacturer 2:upc 5:short_description 10: 4:category 6: 7:url 
8:image 9: 0:name 1:mpn 3:sku]

Second one:

map[3:manufacturer 5:mpn 8:category_path 10:is_in_stock 2:final_price 
1:name 4:short_description 6:thumbnail 7:url 9:furniture_type 0:sku]
map[news_to_date:2014-10-20 00:00:00 url_key:zanbury-panel-storage- 
bedroom-set price:0 media_gallery:[map[value_id:507779 file:/b/2/b217- 
31-36-46-57-54s-95-92.jpg label:<nil> disabled:0 position:1] 
map[label:<nil> disabled:0 position:2 value_id:507777 file:/b/2/b217- 
57-54s-95_1.jpg] map[value_id:507778 file:/b/2/b217-57-detail_3.jpg 
label:<nil> disabled:0 position:3] map[value_id:507780 file:/b/2/b217- 
54s-detail_1.jpg label:<nil> disabled:0 position:4] 
map[file:/b/2/b217-handle_1.jpg label:<nil> disabled:0 position:5 
value_id:507781] map[value_id:507782 file:/b/2/b217-92-sw_1.jpg label: 
<nil> disabled:0 position:6] map[value_id:507783 file:/b/2/b217-31-36- 
sw_-_copy_2_.jpg label:<nil> disabled:0 position:7] 
map[value_id:507784 file:/b/2/b217-46-sw_1.jpg label:<nil> disabled:0 
position:8]] sku_8:<nil> sku_1:<nil> shipment_type:0 url_path:zanbury- 
panel-storage-bedroom-set.htm custom_design:<nil> sku_5:<nil> upc: 
<nil> special_from_date:<nil> mk_expecdate:<nil> sku_type:1 
has_options:1 price_view:0 jet_price:<nil> categories:[11 10809]

How I can compare both and select those values from the second one which matches the first one.

  • 写回答

2条回答 默认 最新

  • drwiupraq047311240 2018-10-01 05:12
    关注

    If I understand your question correctly, the following should work:

    Step I. Reverse keys and values in your 2nd map: reversed_map_2. This assumes that the values are unique.

    Step II. Loop over values in your 1st map, now you can look up the values in reversed_map_2

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题