reverse/inverse a mapping but with multiple values for each key
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的更多相关文章
- [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 ...
- python报错 TypeError: a() got multiple values for argument 'name'
[问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError: got multiple values for argument 只是很简单的调用 from tsu2Ru ...
- Coroutines in Android - One Shot and Multiple Values
Coroutines in Android - One Shot and Multiple Values 在Android中, 我们用到的数据有可能是一次性的, 也有可能是需要多个值的. 本文介绍An ...
- 跨域: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 ...
- 跨域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 '*, *', ...
- 【问题解决】'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
问题复述 今天项目组有人找我说之前部署的程序在测试环境没问题,到生产环境出现了奇怪的问题,点按钮没反应. 我通过腾讯会议发现他们的浏览器控制台上打出了如下错误: Access to XMLHttpRe ...
- [Falcor] Retrieving Multiple Values
In addition to being able to retrieve a path from a Falcor Model, you can also retrieve multiple Pat ...
- TypeError: test() got multiple values for keyword argument 'key'
原因是: 1.函数调用的最终形式只会调用两个函数.一个list参数和一个dict参数,格式为call(func, list, dict); 2.如果传入参数中有key参数,那么首先key参数(包括扩展 ...
- Python TypeError: __init__() got multiple values for argument 'master'(转)
转自:https://stackoverflow.com/questions/33153404/python-typeerror-init-got-multiple-values-for-argume ...
随机推荐
- Jvm组成以及调优
Jvm的内存由三部分组成Eden,S0,S1,Old以及Metaspace(JDK1.8之前的Perm区)五部分组成: (图片摘自VisualVM的Visual GC插件) 抽象为三代:新生代(Ede ...
- Delphi回车键切换焦点
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- eclipse和myeclipse怎么在项目中查找指定代码?https://www.jb51.net/softjc/554889.html
有的童鞋,想eclipse和myeclipse整个项目中查找指定代码,由于补经常使用,可能会补熟悉.如果要去掉项目中所有的某个代码的话,找不到是灰常麻烦的,下面就简单说下怎么查找,希望对需要的人有用. ...
- HttpClient设置忽略SSL,实现HTTPS访问, 解决Certificates does not conform to algorithm constraints
话不多说,直接上代码. 测试API: https://api.k780.com/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f7 ...
- Java ——补充:构造方法 super()与构造方法 无参 有参构造方法 this()与构造方法
参考文章: https://blog.csdn.net/qq_33322074/article/details/86030836 https://blog.csdn.net/HD243608836/a ...
- 【转载】PHP中foreach的用法
http://www.php.cn/php-weizijiaocheng-399438.html 很好用的PHP中foreach的用法详解,收藏!
- 【Linux开发】Linux启动脚本设置
前言linux有自己一套完整的启动 体系,抓住了linux启动 的脉络,linux的启动 过程将不再神秘.阅读之前建议先看一下附图.本文中假设inittab中设置的init tree为:/etc/rc ...
- 006 Notepad++ 运行 C/C++
目录 0. 前言 1. 准备 2. 开工 setp 1 step 2 step 3 step 4 step 5 step 6 3. 修改与删除 3.1修改名称.快捷键 3.2 删除 4. 运行 5. ...
- java8--- Optional的使用
// https://www.jianshu.com/p/82ed16613072 1.Optional.of(T value),传入非 null(否则会抛出 NullPointerException ...
- net 架构师-数据库-sql server-002-工具
本章讲述的工具包括: SQL Server 联机丛书 SQL Server配置管理器 SQL Server Management Studio SQL Server Business Intellig ...