I have two list in same size in python and want to merge them to become one list with the same number size as before
first one :
['add ', 'subtract ', 'multiply ', 'divide ']
second one :
[3, 2, 3, 2]
and i want output came like :
['add 3', 'subtract 2', 'multiply 3', 'divide 2']
How can I do that?
I tried this:
list3 = functions_name + main_function_count
but the output is :
['add ', 'subtract ', 'multiply ', 'divide ', 3, 2, 3, 2]
Use a combination of list comprehension with zip and f-strings
list1 = ['add ', 'subtract ', 'multiply ', 'divide ']
list2 = [3, 2, 3, 2]
result = [f'{x} {y}' for x, y in zip(list1, list2)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With