python 列表中删除 部分一些符合条件的值
list=[None,None,None,None,"a","b","c",None,"d",12,None,2,4,5,4]1.我要删除前面四个None,后面的两个No...
list=[None,None,None,None,"a","b","c",None,"d",12,None,2,4,5,4]
1. 我要删除前面四个None, 后面的两个None需要保留
2. 数从"a"到最后 4 之间一共几值. (包括中间的两个"None") 展开
1. 我要删除前面四个None, 后面的两个None需要保留
2. 数从"a"到最后 4 之间一共几值. (包括中间的两个"None") 展开
3个回答
展开全部
>>> list =[None,None,None,None,"a","b","c",None,"d",12,None,2,4,5,4]
>>> list = list[4:]
>>> len(list)
11
>>> list
['a', 'b', 'c', None, 'd', 12, None, 2, 4, 5, 4]
>>>
#如果你的list 格式是相同的 比如前面4个都是None,这个格式是固定的,那么切片很容易解决
追问
问题就是要确定前面有几个None.. 谢谢
追答
tmp = []
list =[None,None,None,None,None,"a","b","c",None,"d",12,None,2,4,5,4]
for i,v in enumerate(list):
if not v:
continue
else:
tmp = list[i:]
break
print tmp
#list 前面是连续的None, 都可以删除
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询