I want to insert a constant element in front of each of the existing list element, i.e. go from:
['foo', 'bar', 'baz']
at
['a', 'foo', 'a', 'bar', 'a', 'baz']
I tried using lists, but the best I can achieve is an array of arrays using this expression:
[['a', elt] for elt in stuff]
The result is the following:
[['a', 'foo'], ['a', 'bar'], ['a', 'baz']]
So not quite what I want. Can this be done using list comprehension? Just in case, this is important; I'm using Python 3.5.
source
share