Python: associates a single element with each element of a list

advertisements

For example: myStr = 'z' is to be paired with myList = ['a','b','c'] so that the output is as follows:

['z','a']
['z','b']
['z','c']

A one-liner would be great!

I tried to do this:

print zip([myStr, x] for x in myList)

But the output was not quite as I wanted, as in here:

[(['z', 'a'],), (['z', 'b'],), (['z', 'c'],)]


Try this:

myList = ['a','b','c']
myStr = 'z'
res = [[myStr, x] for x in myList]