Slip 28 - B) Write a Python program to accept two lists and merge the two lists into list of tuple.

 Solution:

lst1=[1,2,3,5]
lst2=["Coding Activity"]

t3=list()
t3.append(lst1)
t3.append(lst2)

t4=[tuple(t3[0]),tuple(t3[1])]
print(t4)


Output:

Output_pic


Post a Comment

1 Comments

  1. # Write a Python program to accept two lists and merge the two lists into list of tuple.

    def merge_lists_to_tuples(list1, list2):
    merged_list = list(zip(list1, list2))
    return merged_list


    list1 = input("Enter the first list of elements (separated by spaces): ").split()
    list2 = input("Enter the second list of elements (separated by spaces): ").split()

    result = merge_lists_to_tuples(list1, list2)
    print("Merged list of tuples:", result)

    ReplyDelete