
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 in Row Range
When it is required to find the maximum value in a row range, a simple iteration and the ‘max’ method is used.
Below is a demonstration of the same −
Example
my_list = [[11, 35, 6], [9, 11, 3], [35, 4, 2],[8, 15, 35], [5, 9, 18], [5, 14, 2]] print("The list is :") print(my_list) i, j = 2, 4 print("The values for integers are ") print(i, j) my_result = 0 for index in range(i, j): my_result = max(max(my_list[index]), my_result) print("The result is :") print(my_result)
Output
The list is : [[11, 35, 6], [9, 11, 3], [35, 4, 2], [8, 15, 35], [5, 9, 18], [5, 14, 2]] The values for integers are 2 4 The result is : 35
Explanation
A list of list is defined and is displayed on the console.
The values for two integers are defined and displayed on the console.
A variable is initialized to 0.
The integers are taken as range values and iterated over.
The maximum of index element is taken, and assigned to the variable.
This is the output that is displayed on the console.
Advertisements