我有样式列表:
[None, ..., None, "c", 1, 3, None, None, 4.3, "b", None, "4", None, ..., None]
我想有效地缩短为:
["c", 1, 3, None, None, 4.3, "b", None, "4"]
直截了当,我可以做到:
def _shorten(long_list):
start = False
short_list = []
for e in long_list:
if e:
start = True
if start:
short_list.append(e)
return short_list
reversed(_shorten(reversed(_shorten(long_list))))