反转元组列表中的元组 [英] Invert tuples in a list of tuples

查看:117
本文介绍了反转元组列表中的元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组[(126,150),(124,154),(123,145),(123,149)](只是一个数字样本,该数组太大,无法显示所有数字),然后使用imshow将结果绘制到矩阵上.我想要的是找到数组的逆,这样[(150,126),(154,124),(145,123),(149,123)]然后执行另一个imshow.

I have an array [(126,150),(124,154),(123,145),(123,149)](just a sample of the numbers, the array is too large to show all of them) which I have then used imshow to plot the results onto a matrix. What I want is to find the inverse of the array so [(150,126),(154,124),(145,123),(149,123)] and then do another imshow.

如何反转数组以实现所需的功能?

How can I inverse the array so it achieves what I want to do?

推荐答案

array = [(126,150),(124,154),(123,145),(123,149)]
inversed = [(item[1],item[0]) for item in array]

这篇关于反转元组列表中的元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆