- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Maximum difference across lists
When it is required to find the maximum difference across the lists, the ‘abs’ and the ‘max’ methods are used.
Below is a demonstration of the same
my_list_1 = [7, 9, 1, 2, 7] my_list_2 = [6, 3, 1, 2, 1] print("The first list is :") print(my_list_1) print("The second list is :") print(my_list_2) my_result = max(abs(my_list_2[index] - my_list_1[index]) for index in range(0, len(my_list_1) - 1)) print("The maximum difference among the lists is :") print(my_result)
The first list is : [7, 9, 1, 2, 7] The second list is : [6, 3, 1, 2, 1] The maximum difference among the lists is : 6
Two lists are defined and are displayed on the console.
The difference between elements of the two lists are taken by iterating through the length of the elements.
The absolute difference between the values is taken, and then the maximum of these differences is taken.
This is stored in a variable.
This is displayed as output on the console.
- Python – Disjoint Strings across Lists
- Difference of two lists including duplicates in Python
- Python program to list the difference between two lists.
- Find Maximum difference pair in Python
- What's the difference between lists and tuples in Python?
- Find Maximum difference between tuple pairs in Python
- Updating Lists in Python
- Plotting grids across the subplots in Python Matplotlib
- What is the difference between del, remove and pop on lists in python ?
- Program to find minimum difference between two elements from two lists in Python
- Adding two Python lists elements
- Dividing two lists in Python
- Multi-dimensional lists in Python
- Python - Intersection of multiple lists
- Maximum Weight Difference in C++