# Python program to find the redundancy rates for each row of a matrix

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

When it is required to find the redundancy rates for every row of a matrix, a simple iteration and the ‘append’ method can be used.

## Example

Below is a demonstration of the same

my_list = [[91, 52, 12, 29, 33], [54, 54, 54, 54, 54], [11, 22, 33, 59, 95]]

print("The list is :")
print(my_list)

my_result = []
for sub in my_list:
my_result.append(1 - len(set(sub)) / len(sub))

print("The result is :")
print(my_result)

## Output

The list is :
[[91, 52, 12, 29, 33], [54, 54, 54, 54, 54], [11, 22, 33, 59, 95]]
The result is :
[0, 1, 0]

## Explanation

• A list of list is defined and is displayed on the console.

• An empty list is created.

• The original list is iterated over, and when a condition is met, it is appended to the empty list.

• This is displayed as the output on the console.

Updated on 15-Sep-2021 11:40:56