Share
Output of List
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Let list1 = [‘s’, ‘r’, ‘a’, ‘s’] and list2 = [‘a’, ‘a’, ‘n’, ‘h’], what is the output of [“”.join([i, j]) for i, j in zip(list1, list2)]
Answers ( 3 )
The output concatenates the elements in list 1 with the elements in list 2 against the corresponding index number
ans=[]
for (i,j) in zip (list1,list2):
x=”.join([i,j])
ans.append(x)
ans
output: [‘sa’, ‘ra’, ‘an’, ‘sh’]
zip function makes a new list with each element as the elements of list1 and list2 “zipped” together.
The list comprehension will output [(‘s’,’a’),(‘r’,’a’),(‘a’,’n’,(‘s’,’h’)]
join function will “join” the 2 characters in each item together and the output would be [‘sa’, ‘ra’, ‘an’, ‘sh’]