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. 【汇总】Wireshark 过滤规则

    作者:Bay0net 时间:2019-07-01 14:20:09 更新: 介绍:记录使用过的 wireshark 过滤规则 0x01. 使用介绍 抓包采用 wireshark,提取特征时,要对 se ...

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

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

  3. seanborn使用函数regplot回归分析绘图

    可以用regplot(x, y, data)绘制回归图.data参数是DataFram类型,x是其中某一列列名,是即将绘制的图的x坐标,y是其中某一列,是图的y坐标 下面代码是对seaborn内置数据 ...

  4. Kotlin-Note

    数字在需要一个可空的引用时,会进行装箱操作,数字装箱不一定保留同一性. val a = 1000 println(a === a) // 输出 "true" val boxedA ...

  5. Centos 安装Jenkins的坎坷

    安装Jenkins(简单复制即可) wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.rep ...

  6. clearfix:after 的用法

    想要清除浮动就要在父元素上 加上 clearfix:after .clearfix:after { <----在类名为“clearfix”的元素内最后面加入内容: content: " ...

  7. 【C语言--数据结构】线性顺序表

    线性表的本质: 1.线性表(List)是零个或者多个数据元素的集合: 2.线性表中的数据元素之间是有顺序的: 3.线性表中的数据元素个数是有限的: 4.线性表中的数据元素的类型必须相同: 定义: 线性 ...

  8. QQ管理

    ##用例1:查询数据 #01.查询QQ号码为54789625的所有好友信息,包括QQ号码,昵称,年龄 # # SELECT `relation`.RelationQQID AS QQ号码,`basei ...

  9. webapi接口统一返回请求时间

    webapi接口统一返回请求时间: public class BaseController : ControllerBase { protected ReturnResult<T> Res ...

  10. 各类最新Asp .Net Core 项目和示例源码

    1.网站地址:http://www.freeboygirl.com2.网站Asp .Net Core 资料http://www.freeboygirl.com/blog/tag/asp%20net%2 ...