PYTHON-如果包含在另一个列表中,则从列表中删除元组 [英] PYTHON - Remove tuple from list if contained in another list

查看:312
本文介绍了PYTHON-如果包含在另一个列表中,则从列表中删除元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元组列表:

list_of_tuples = [('4', 35.26), ('1', 48.19), ('5', 90.0), ('3', 90.0)]

tuple [0]是item_ID

tuple[0] is an item_ID

tuple [1]是一个角度

tuple[1] is an angle

我有一个要从列表中删除/忽略的item_ID列表:

I have a list of item_IDs I want to remove/ignore from the list:

ignore_IDs = [5, 3]

我需要在list_of_tuples中找到最小的角度,只要它的ID不在ignore_ID中即可.

I need to find the smallest angle in the list_of_tuples as long as its ID is not in ignore_IDs.

此功能用于角度发生变化且ID可以忽略的函数中.

This is used in a function where the angles change and the IDs to ignore change.

有人可以帮我吗?

道歉,如果不好解释.

推荐答案

如果我没有误解的话,会发生类似的事情:

Something like this would do, if I didn't misunderstood:

min([t[1] for t in list_of_tuples if int(t[0]) not in ignore_IDs])

这篇关于PYTHON-如果包含在另一个列表中,则从列表中删除元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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