python列表去除none_从Python列表中删除None

我有一份清单如下:[None, None, None, None, [(udata1, 2.0, 2.0, 1.0, 1.0, 2015-10-01, 2015-10-01)], None, None, None, None, [(udata2, 8.0, 5.0, 0.625, 1.25, 2015-10-01, 2015-10-01)], None, None, None, None, None, None, [(udata3, 1.0, 1.0, 1.0, 1.0, 2015-10-01, 2015-10-01)], None, None, None, None, None, None, None, None, None, None, None, None, None]

我需要删除None,这样我就可以遍历列表了。如果值为None,我应该不插入,还是在插入后从列表中删除它们?在

我正在构建这样的列表:

^{pr2}$

前5个值是不返回任何值的值。但看看数据,有时只插入4个“无”,有时插入5个。在

我尝试了stack的几种解决方案,例如:[x for x in result is not None]

以及if val is not None:

item = (val1, val2, val3, val4, val5, start_date, end_date)

array.append(item)

但由于某些原因,即使val为None,它仍将追加。在

我有一份清单如下:[None, None, None, None, [(udata1, 2.0, 2.0, 1.0, 1.0, 2015-10-01, 2015-10-01)], None, None, None, None, [(udata2, 8.0, 5.0, 0.625, 1.25, 2015-10-01, 2015-10-01)], None, None, None, None, None, None, [(udata3, 1.0, 1.0, 1.0, 1.0, 2015-10-01, 2015-10-01)], None, None, None, None, None, None, None, None, None, None, None, None, None] 我需要删除None,这样我就可以遍历列表了。如果值为None,我应该不插入,还是在插入后从列表中删除它们?在 我正在构建这样的列表: ^{pr2}$ 前5个值是不返回任何值的值。但看看数据,有时只插入4个“无”,有时插入5个。在 我尝试了stack的几种解决方案,例如:[x for x in result is not None] 以及if val is not None: item = (val1, val2, val3, val4, val5, start_date, end_date) array.append(item) 但由于某些原因,即使val为None,它仍将追加。在
经验分享 程序员 微信小程序 职场和发展