根据元组中的字典值删除元组列表中的元组

问题描述

我有一长串包含字典的元组。我想删除“权重”值为1的元组

List_example = [('WHT','WML,{'weight': 48}),('WHHT','CCH',{'weight': 53}),('WRT','KUF',{'weight': 1}),'RWH',{'weight': 1}))]

所需的输出

List_example = [('WHT',{'weight': 53}))]

解决方法

下方

lst = [('WHT','WML',{'weight': 48}),('WHHT','CCH',{'weight': 53}),('WRT','KUF',{'weight': 1}),'RWH',{'weight': 1})]
 
new_lst = [x for x in lst if x[2]['weight'] != 1]
print(new_lst)

输出

[('WHT',{'weight': 53})]