- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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 - Count the frequency of matrix row length

When it is required to count the frequency of the matrix row length, it is iterated over and its frequency is added to the empty dictionary or incremented if found again.

## Example

Below is a demonstration of the same

my_list = [[42, 24, 11], [67, 18], [20], [54, 10, 25], [45, 99]] print("The list is :") print(my_list) my_result = dict() for element in my_list: if len(element) not in my_result: my_result[len(element)] = 1 else: my_result[len(element)] += 1 print("The result is :") print(my_result)

## Output

The list is : [[42, 24, 11], [67, 18], [20], [54, 10, 25], [45, 99]] The result is : {1: 1, 2: 2, 3: 2}

## Explanation

A list is defined and is displayed on the console.

An empty dictionary is defined.

The list is iterated over, and if the specific length is not present in the dictionary, the length in the dictionary is assigned to 1.

Otherwise, it is incremented by 1.

This is the output that is displayed on the console.

- Related Questions & Answers
- Custom length Matrix in Python
- Count Frequency of Highest Frequent Elements in Python
- Program to find length of longest matrix path length in Python
- Python program to count distinct words and count frequency of them
- Python – Sort Matrix by None frequency
- Count frequency of k in a matrix of size n where matrix(i, j) = i+j in C++
- Python – Count frequency of sublist in given list
- Get the average row length of a MySQL table
- Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix using Python?
- Count of elements of an array present in every row of NxM matrix in C++
- Python – Sort Matrix by Row Median
- Python - Sort Matrix by Maximum Row element
- Check if the frequency of any character is more than half the length of the string in Python
- Python Program that prints the rows of a given length from a matrix
- Python program to find the redundancy rates for each row of a matrix

Advertisements