我如何在python中摆脱额外的数组?

时间:2014-09-24 15:08:12

标签: python list

所以我的代码如下:

  promotion = [[""], ["promotion applied"],[""]]

如何让它从那里进入这种状态:

 promotion = ["", "promotion applied", ""]

1 个答案:

答案 0 :(得分:1)

使用list comprehension

>>> promotion = [[""], ["promotion applied"],[""]]
>>> [x[0] for x in promotion]
['', 'promotion applied', '']

with tuple unpacking:

>>> [x for x, in promotion]  # works only if all items are single-item sequences.
['', 'promotion applied', '']