我们都很清楚,我们可以在python列表中插入大量的数据类型。例如,字符列表
X=['a','b','c']
要去掉“c”,我要做的就是
X.remove('c')
现在我需要的是移除一个包含特定字符串的对象。你知道吗
class strng:
ch = ''
i = 0
X = [('a',0),('b',0),('c',0)] #<---- Assume The class is stored like this although it will be actually stored as object references
Object = strng()
Object.ch = 'c'
Object.i = 1
X.remove('c') #<-------- Basically I want to remove the Object containing ch = 'c' only.
# variable i does not play any role in the removal
print (X)
[('a',0),('b',0)] #<---- Again Assume that it can output like this
我想你想要的是:
以下函数将在条件为
True
的情况下删除所有项:以下是如何使用它:
为了名单
如果知道元组的第一项始终是字符串,并且如果该字符串具有不同的值,则要删除该字符串,请使用列表:
输出如下:
相关问题 更多 >
编程相关推荐