Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String in list multiplied by item in another list, printed on separate lines

Basically:

list1 = ['x', 'y', 'z']
list2 = [1, 2, 3]

And I want my output to be in the form of

x
y
y
z
z
z

I have

for i in range(0,len(list1)):
   output = list1[i] * list2[i]
   print(output)

But that only gets me

x
yy
zzz
like image 833
user3613243 Avatar asked Feb 13 '23 01:02

user3613243


1 Answers

Take the advantage of print() function:

>>> from operator import mul
>>> for x in map(mul, list1, list2):
    print(*x, sep='\n')
...     
x
y
y
z
z
z
like image 92
Ashwini Chaudhary Avatar answered Feb 16 '23 04:02

Ashwini Chaudhary