Output of List

Question

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)]

in progress 0
TheDataMonk 55 years 3 Answers 608 views Grand Master 0

Answers ( 3 )

  1. The output concatenates the elements in list 1 with the elements in list 2 against the corresponding index number

  2. ans=[]
    for (i,j) in zip (list1,list2):
    x=”.join([i,j])
    ans.append(x)
    ans

    output: [‘sa’, ‘ra’, ‘an’, ‘sh’]

  3. 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’]

Leave an answer

Browse
Browse