how do i get rid of extra array in python?

Question:

so my code is as follows:

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

how do I make it go from there to this state:

 promotion = ["", "promotion applied", ""]
Asked By: slopeofhope

||

Answers:

Using 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', '']
Answered By: falsetru
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.