reverse/inverse a mapping but with multiple values for each key

multi mappping dictionary , reverse/inverse

'''
mrg_dictionary: {15: {16, 19, 21, 23}, 22: {18}}
inv_merging_led_dict: {16: 15, 19: 15, 21: 15, 23: 15, 18: 22}
mrg_dictionary --> inv_merging_led_dict
'''
mrg_dictionary = {15: {16, 19, 21, 23}, 22: {18}}
inv_merging_led_dict = {value:key for key in mrg_dictionary for value in mrg_dictionary[key]}
print(inv_merging_led_dict) '''
inv_merging_led_dict: {16: 15, 19: 15, 21: 15, 23: 15, 18: 22}
mrg_dictionary: {15: {16, 19, 21, 23}, 22: {18}}
inv_merging_led_dict --> mrg_dictionary
'''
valueset = set(inv_merging_led_dict.values())
mrg_dictionary = {k:set() for k in valueset} # {15:set, 18:set()}
for key in mrg_dictionary.keys():
pop_k_list = []
for k in inv_merging_led_dict:
if inv_merging_led_dict[k] == key:
mrg_dictionary[key].add(k)
pop_k_list.append(k)
for k in pop_k_list:
inv_merging_led_dict.pop(k) print('mrg_dictionary', mrg_dictionary)

reverse/inverse a mapping but with multiple values for each key的更多相关文章

  1. [Go] Returning Multiple Values from a Function in Go

    Returning multiple values from a function is a common idiom in Go, most often used for returning val ...

  2. python报错 TypeError: a() got multiple values for argument 'name'

    [问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError:  got multiple values for argument 只是很简单的调用 from tsu2Ru ...

  3. Coroutines in Android - One Shot and Multiple Values

    Coroutines in Android - One Shot and Multiple Values 在Android中, 我们用到的数据有可能是一次性的, 也有可能是需要多个值的. 本文介绍An ...

  4. 跨域:The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed

    https://blog.csdn.net/q646926099/article/details/79082204 使用Ajax跨域请求资源,Nginx作为代理,出现:The 'Access-Cont ...

  5. 跨域The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.解决方案

    使用Ajax跨域请求资源,Nginx作为代理,出现:The 'Access-Control-Allow-Origin' header contains multiple values '*, *', ...

  6. 【问题解决】'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.

    问题复述 今天项目组有人找我说之前部署的程序在测试环境没问题,到生产环境出现了奇怪的问题,点按钮没反应. 我通过腾讯会议发现他们的浏览器控制台上打出了如下错误: Access to XMLHttpRe ...

  7. [Falcor] Retrieving Multiple Values

    In addition to being able to retrieve a path from a Falcor Model, you can also retrieve multiple Pat ...

  8. TypeError: test() got multiple values for keyword argument 'key'

    原因是: 1.函数调用的最终形式只会调用两个函数.一个list参数和一个dict参数,格式为call(func, list, dict); 2.如果传入参数中有key参数,那么首先key参数(包括扩展 ...

  9. Python TypeError: __init__() got multiple values for argument 'master'(转)

    转自:https://stackoverflow.com/questions/33153404/python-typeerror-init-got-multiple-values-for-argume ...

随机推荐

  1. 编写shell脚本一键启动 重启 停止springboot项目

    #!/bin/bash #设置环境变量 export JAVA_HOME=/usr/local/jdk1.8.0_181 export JRE_HOME=/$JAVA_HOME/jre export ...

  2. nginx重要特性

    反向代理负载均衡实现高并发 1.反向代理反向代理(Reverse Proxy)方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器:并将从服务器上得到的结果返回给 ...

  3. Debian系列Linux的隐藏WiFi

    Debian系列Linux共用相同的deb安装包,拥有大量的各种软件,是Linux里面最主要的生态系.包括Ubuntu及其衍生版本如Lubuntu/Mate/Kubuntu等,在ARM上也有很好的支持 ...

  4. node-webkit-updater——NW.js自动更新

    NW.js自动更新三种方案: 1)node-webkit-updater(推荐) 2)nwjs-autoupdater 3)nw-autoupdater NW.js自动更新三种方案:[http://d ...

  5. 那些搜过很多遍的python基础知识

    一. DataFrame 相关 1 索引的使用(.loc[] .iloc[]) .loc用行列标签来选择数据..iloc 根据行数与列数索引. import pandas as pd data = p ...

  6. 2.proxychains----Macchanger----anonsurf

    nano /etc/proxychains.conf 激活dynamic_chain 同是启用proxy_dns 只启用IP会泄露DNS位置信息,别人就知道你在用匿名 ipconfig    ifco ...

  7. TensorFlow2.0矩阵与向量的加减乘

    1.矩阵加法使用 a = np.random.random((3,3))b = np.random.randint(0,9,(3,3)) ad = tf.add(a,b) 2.矩阵乘法注意 # ten ...

  8. 第八周zuoye

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/homew ...

  9. PC端微信防撤回功能分析

    1.打开PC端微信的安装目录,有一个WeChatWin.dll文件,微信的所有功能基本上都在这个文件中了 2.OD打开,搜索字符串revokemsg(撤回消息,掌握一门外语是多么的重要啊!!!),在所 ...

  10. 2019 NCTF Re WP

    0x01 debug 测试文件:https://www.lanzous.com/i7kr2ta 1.Linux运行环境 在Linux上运行linux_server64文件 2.IDA配置 __int6 ...