我有一个字典,其中键是表示y线坐标(y0,y1)的元组,其中y0=线y坐标的底部,y1=y线顶部坐标
data = { (622, 633): 'text1', (604, 619) : 'text2', (596, 633) : 'text3', (577, 587) : 'text4', (551, 587) : 'text5' }
我希望能够“压缩”字典,以便所有与元组相关且重叠的项都在tuple键下组合在一起,其范围最大为y0,y1。所以上面的字典应该是这样的:
^{pr2}$我是python的新手,在这个问题上我有点头晕,希望能朝正确的方向点头。谢谢。
比如说:
编辑:为Python3做了一些调整
相关问题 更多 >
编程相关推荐