- 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 program to extract rows with common difference elements
When it is required to extract rows with common difference elements, an iteration and a flag value is used.
Below is a demonstration of the same
my_list = [[31, 27, 10], [8, 11, 12], [11, 12, 13], [6, 9, 10]] print("The list is :") print(my_list) my_result =  for row in my_list: temp = True for index in range(0, len(row) - 1): if row[index + 1] - row[index] != row - row: temp = False break if temp : my_result.append(row) print("The resultant list is :") print(my_result)
The list is : [[31, 27, 10], [8, 11, 12], [11, 12, 13], [6, 9, 10]] The resultant list is : [[11, 12, 13]]
A list of tuple is defined and is displayed on the console.
An empty list is created.
The list is iterated over, and a variable is assigned to ‘True’.
The indices are also iterated over.
If the difference between previous index and current index is not equal to the difference between the previous element and current element, the variable is assigned ‘False’.
The control breaks out of it.
In the end, if the variable’s value is ‘True’, the element is appended to the empty list.
This is the output that is displayed on the console.
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Python program to extract Mono-digit elements
- Python – Extract rows with Even length strings
- Python – Extract rows with Complex data types
- Find distinct elements common to all rows of a matrix in Python
- Python – Extract Paired Rows
- Python Program to Sort Matrix Rows by summation of consecutive difference of elements
- Python program to find common elements in three sorted arrays?
- Python – Extract tuples with elements in Range
- Python – Filter rows with required elements
- Python – Filter Rows with Range Elements
- Python – Rows with all List elements
- Python program to extract rows from Matrix that has distinct data types
- Python program to print all the common elements of two lists.
- Python program to find common elements in three lists using sets