- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 using map function to find row with maximum number of 1's

In this article, we will learn how to use map function to find row with maximum number of 1's. 2D array is given and the elements of the arrays are 0 and 1. All rows are sorted. We have to find row with maximum number of 1's. Here we use map (). The map function is the simplest one among Python built-ins used for functional programming. These tools apply functions to sequences and other iterables.

Let’s say the input is the following array −

[[0, 1, 1, 1, 1],[0, 0, 1, 1, 1],[1, 1, 1, 1, 1],[0, 0, 0, 0, 1]]

Output displays the row with maximum number of 1s −

2

## Find row with maximum number of 1's

In this example, we will find a row with maximum number of 1’s using the map() function −

### Example

def maximumFunc(n): max1 = list(map(sum,n)) print ("Row with maximum number of 1s = ",max1.index(max(max1))) # Driver program if __name__ == "__main__": n = [[0, 1, 0, 1, 1],[1, 0, 0, 0, 1],[1, 1, 1, 0, 1]] maximumFunc(n)

### Output

Row with maximum number of 1s = 2

## Find row with maximum number of 1's using for loop

In this example, we will find a row with maximum number of 1’s using a for loop simply −

### Example

m = [[0, 1, 0, 1, 1],[1, 0, 1, 0, 1],[1, 0, 1, 0, 1]] mrows = len(m) max1 = 0 for k in range(mrows): c = m[k].count(1) if(c >= max1): max1 = c res = k+1 print("The row with maximum number of 1s = ", res)

### Output

The row with maximum number of 1s = 3

- Related Articles
- Python program using the map function to find a row with the maximum number of 1's
- Python map function to find the row with the maximum number of 1’s
- Maximum length of consecutive 1’s in a binary string in Python using Map function
- Find the row with maximum number of 1s using C++
- Program to find maximum number of non-overlapping subarrays with sum equals target using Python
- Program to find path with maximum probability using Python
- Program to find maximum number of balls in a box using Python
- Program to find maximum number of coins we can get using Python
- Program to find number of square submatrices with 1 in python
- Program to find the nth row of Pascal's Triangle in Python
- Program to find maximum number of eaten apples in Python
- Program to find number of substrings with only 1s using Python
- Program to find maximum sum by flipping each row elements in Python
- Find the maximum element of each row in a matrix using Python
- Program to find maximum population year using Python

Advertisements