- 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 – Consecutive Division in List
When it is required to find the consecutive division in a list, a method is defined that iterates over the elements of the list and uses the ‘/’ operator to determine the result.
Below is a demonstration of the same −
def consec_division(my_list): my_result = my_list for idx in range(1, len(my_list)): my_result /= my_list[idx] return my_result my_list = [2200, 500, 100, 50, 20, 5] print("The list is :") print(my_list) my_result = consec_division(my_list) print("The result is :") print(my_result)
The list is : [2200, 500, 100, 50, 20, 5] The result is : 8.8e-06
A method named ‘consec_division’ is defined that takes a list as a parameter.
It assigns the zeroth index to a variable.
The list is iterated over, and the ‘/’ operator is used to divide every element by the first element.
This is returned as result.
Outside the method, a list is defined and is displayed on the console.
The method is called by passing the list.
This is assigned to a variable.
It is displayed as output on the console.
- Consecutive elements pairing in list in Python
- Check if list contains consecutive numbers in Python
- Division Operators in Python?
- Tuple Division in Python
- Consecutive Nth column Difference in Tuple List using Python
- Average of each n-length consecutive segment in a Python list
- Longest Consecutive Sequence in Python
- Remove Consecutive Duplicates in Python
- Python – Extract range of Consecutive similar elements ranges from string list
- Check if absolute difference of consecutive nodes is 1 in Linked List in Python
- How to perform the Integer division operation of a pandas Series by a Python list?
- Consecutive element maximum product in Python
- Swap Consecutive Even Elements in Python
- Python – Extend consecutive tuples
- Python - Selective consecutive Suffix Join