[SOLVED] zip function in python for lists


If I use the zip function than I am not getting the desired output. I want to combine two lists which are as follows:-
list1 = []
list2 = [0]

I want the output as [0].
If I am using zip(list1,list2) I am getting [] as output.

I don’t want to use any method other than zip. Is there any way I could get the output using zip function?


The issue is that zip is not used to achieve merging your lists

Here is the correct implementation

list1 = []
list2 = [0]

# result output: [0]

However, zip function is used as an iterator between lists. below is an example to help you with the concept

a = ("1", "2", "3")
b = ("A", "B", "C")

x = zip(a, b)

for i in x:  # will loop through the items in x

# result output:  
# ('1', 'A')
# ('2', 'B')
# ('3', 'C')

Answered By – Youstanzr

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *