Q:

Create a Python set such that it shows the element from both lists in a pair using python programming

belongs to collection: Python Data Structure Exercises

0

Create a Python set such that it shows the element from both lists in a pair

Given:

first_list = [2, 3, 4, 5, 6, 7, 8]
second_list = [4, 9, 16, 25, 36, 49, 64]

Expected Output:

Result is  {(6, 36), (8, 64), (4, 16), (5, 25), (3, 9), (7, 49), (2, 4)}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the zip() function. This function takes two or more iterables (like list, dict, string), aggregates them in a tuple, and returns it.

Solution:

first_list = [2, 3, 4, 5, 6, 7, 8]
print("First List ", first_list)

second_list = [4, 9, 16, 25, 36, 49, 64]
print("Second List ", second_list)

result = zip(first_list, second_list)
result_set = set(result)
print(result_set)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Find the intersection (common) of two sets and rem... >>
<< Slice list into 3 equal chunks and reverse each ch...