如何从循环列表中删除 int/float 的二元组?
How to remove a 2-tuple of int/float from a list in a loop?
所以如果我有一个列表:
x = [(1,3.),(2,4.),(5,6), (6,6.)]
我如何才能删除第二个(如果是索引术语,则为第一个)项为 6 的项?它看起来像:
x = [(1,3.),(2,4.)]
我试过的代码总是给我错误:
TypeError: 'float' object is not subscriptable
或
TypeError: 'int' object is not subscriptable
您可以使用列表理解:
x = [item for item in x if item[1] != 6]
所以如果我有一个列表:
x = [(1,3.),(2,4.),(5,6), (6,6.)]
我如何才能删除第二个(如果是索引术语,则为第一个)项为 6 的项?它看起来像:
x = [(1,3.),(2,4.)]
我试过的代码总是给我错误:
TypeError: 'float' object is not subscriptable
或
TypeError: 'int' object is not subscriptable
您可以使用列表理解:
x = [item for item in x if item[1] != 6]