Python: Common index elements from more than one list
Python List: Exercise - 100 with Solution
Write a Python program to extract common index elements from more than one given list.
def extract_index_ele(l1, l2, l3): result =  for m, n, o in zip(l1, l2, l3): if (m == n == o): result.append(m) return result nums1 = [1, 1, 3, 4, 5, 6, 7] nums2 = [0, 1, 2, 3, 4, 5, 7] nums3 = [0, 1, 2, 3, 4, 5, 7] print("Original lists:") print(nums1) print(nums2) print(nums3) print("\nCommon index elements of the said lists:") print(extract_index_ele(nums1, nums2, nums3))
Original lists: [1, 1, 3, 4, 5, 6, 7] [0, 1, 2, 3, 4, 5, 7] [0, 1, 2, 3, 4, 5, 7] Common index elements of the said lists: [1, 7]
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to find the maximum and minimum values in a given heterogeneous list.
Next: Write a Python program to sort a given matrix in ascending order according to the sum of its rows.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Big Number Readability:
you can separate zeros with underscore (_)
print(2_000_000) print(2_000_000 +1)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework