Ask Question
4 May, 10:15

5. Write a function that takes two lists of integers and returns a list containing tuples with corresponding elements from both the lists. For example - f ([1, 2, 3], [4, 5, 6]) - > [ (1, 4), (1,5), (1,6), (2, 4), (2, 5), (2, 6), (3, 4), (3,5), (3, 6) ]. If either list is null, the result is null. The lists do not have to be the same length.

+2
Answers (1)
  1. 4 May, 10:25
    0
    def corresponding_of_lists (lst1, lst2):

    c = ""

    corresponding_list = []

    if (lst1 is None) or (lst2 is None):

    return None

    else:

    for i in lst1:

    for j in lst2:

    c = " (" + str (i) + "," + str (j) + ") "

    corresponding_list. append (c)

    return corresponding_list

    Explanation:

    - Create a function called corresponding_of_lists that takes two lists as parameter

    - Initialize an empty list to hold the corresponding values

    - Check if any of the lists are null, if they are return None

    - Otherwise, get the corresponding elements and put them into the corresponding_list

    Return the corresponding_list
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “5. Write a function that takes two lists of integers and returns a list containing tuples with corresponding elements from both the lists. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers