I define:
A = [[1, 2], [3, 4], [5, 6]]
What is/are the line/s producing:
B = [['hello', [1, 2]], ['hello', [3, 4]], ['hello', [5, 6]]]
I define:
A = [[1, 2], [3, 4], [5, 6]]
What is/are the line/s producing:
B = [['hello', [1, 2]], ['hello', [3, 4]], ['hello', [5, 6]]]
You can add 'hello'
to the front of each list with a list comprehension:
>>> add = 'hello'
>>> A = [[1, 2], [3, 4], [5, 6]]
>>> [[add, x] for x in A]
[['hello', [1, 2]], ['hello', [3, 4]], ['hello', [5, 6]]]
# or [[add] + [x] for x in A]
This may be helpful:
B = zip(['hello'] * len(A), A)
This will produces following result: [('hello', [1, 2]), ('hello', [3, 4]), ('hello', [5, 6])]
If you need lists instead of tuples, you can use following code:
B = list(map(list, zip(['hello'] * len(A), A)))