【发布时间】:2017-07-29 09:16:56
【问题描述】:
我有我的
datacount= ([('mark / 222696_at', 19), ('jason / 210393_at', 15), ('mickey / 213880_at', 15), ('mo / 228649_at', 13), ('nick / 229481_at', 12), ('nikoo / 1553115_at', 12), ('- / 229613_at', 12)]
但我想删除列表中以“- / 2”开头的元组,例如('- / 229613_at', 12)。
我试过了,
datacount = [x for x in datacount if x[0] not in ['str.startwith(- / 2) == True']]
但是 ('- / 229613_at', 12), ('- / 232203_at', 11),('- / 244174_at', 6), ('- / 237146_at', 6) 等结果仍然会出现。
【问题讨论】:
-
'str.startwith(- / 2) == True'是字符串,不是 python 表达式... -
datacount是元组还是列表?因为它以元组开始,以列表结束... -
我用过这个,它有效 datacount = [x for x in datacount if not x[0].startswith("- / ")] 对不起,它的列表,里面有元组。
标签: python list tuples python-3.5