是否可以转换它:
[ [0], [1], [2], [3], [4], [5], [[6,9]], [7], [8], [[6,9]] ]
进入这个:
[ [0], [1], [2], [3], [4], [5], [6,9], [7], [8], [6,9] ]
答案 0 :(得分:2)
你可以这样做:
x = [i[0] if (type(i[0])==list and len(i[0])>1) else i for i in a]
>>> a = [ [0], [1], [2], [3], [4], [5], [[6,9]], [7], [8], [[6,9]] ]
>>> x = [i[0] if (type(i[0])==list and len(i[0])>1) else i for i in a]
>>> x
[[0], [1], [2], [3], [4], [5], [6, 9], [7], [8], [6, 9]]
答案 1 :(得分:2)
[item if isinstance(item, list) else [item] for items in data for item in items]
# [[0], [1], [2], [3], [4], [5], [6, 9], [7], [8], [6, 9]]
答案 2 :(得分:0)
你可以这样做:
>>> data = [ [0], [1], [2], [3], [4], [5], [[6,9]], [7], [8], [[6,9]] ]
>>> o_data = [a[0] if isinstance(a[0], list) else a for a in data]
>>> o_data
[[0], [1], [2], [3], [4], [5], [6, 9], [7], [8], [6, 9]]