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. Unity 实现物体拖拽

    Unity实现拖拽: 也可以继承Unity EventSystem中的接口实现. 当鼠标按下的时候以左键为例: Using System.Collections; Using System.Colle ...

  2. Debian或者Ubuntu中安装secureCRT/secureFX

    1.官网下载 ubuntu 下的 xx.deb安装包.此处使用的安装包是scrt-sfx-8.5.4-1942.ubuntu16-64.x86_64.deb,点击下载,提取码:5em3. 2.安装 d ...

  3. Android下Native的so编译:使用ndk-build.cmd/.sh

    最近将一个DLL库移植至安卓下,编译出so文件. 经历makefile.cmake等等的入门到放弃..... 最后还是使用android的ndk编译命令来解决 每个NDK文件下,均包含的是所有工具链. ...

  4. [LeetCode] 272. Closest Binary Search Tree Value II 最近的二叉搜索树的值 II

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  5. Chapter02 第三节 其他语句

    2.3 其他语句 // getinfo.cpp #include <bits/stdc++.h> using namespace std; int main() { int carrots ...

  6. “EndExecuteNonQuery”方法没有任何重载采用“0”个参数

    EndExecuteNonQuery需要参数IAsyncResult asyncResult myCmd.ExecuteNonQuery();//执行 ExecuteNonQuery 返回受影响行数

  7. Cocos2d-x-javaScript 的webSocket的代码

    var WebSocket = WebSocket || window.WebSocket || window.MozWebSocket; var WebSocketManager = cc.Clas ...

  8. Java——自定义外部字体文件

    package chapter1; import javax.swing.*;import java.awt.*;import java.io.IOException;import java.io.I ...

  9. maven联通网络下中央仓库不能访问的解决办法

    最近刚开始学习maven工具,下载解压完毕,环境变量配置完毕,运行如下命令尝试快速构建一个maven项目: mvn archetype:generate 结果就有问题: [INFO] Scanning ...

  10. netperf编译./configure时报错 "error: cannot guess build type;you nust specify one"

    问题: 解决办法-亲测可用: 尝试:./configure --build=mingw提示无法辨别 checking build system type... Invalid configuratio ...