Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

PYTHON - Remove tuple from list if contained in another list

I have a list of tuples:

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

tuple[0] is an item_ID

tuple[1] is an angle

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

ignore_IDs = [5, 3]

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

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

Can anyone help me out?

Apologies if explained badly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...