- 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 – Calculate the percentage of positive elements of the list
When it is required to calculate the percentage of positive elements of the list, a list comprehension and the ‘len’ method are used.
Below is a demonstration of the same −
my_list = [14, 62, -22, 13, -87, 0, -21, 81, 29, 31] print("The list is :") print(my_list) my_result = (len([element for element in my_list if element > 0]) / len(my_list)) * 100 print("The result is :") print(my_result)
The list is : [14, 62, -22, 13, -87, 0, -21, 81, 29, 31] The result is : 0
A list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and check if an element is greater than 0, and these elements are divided by product of length of list and 100.
The length of the above operation is assigned to a variable.
This is the output that is displayed on the console.
- Get positive elements from given list of lists in Python
- Java program to calculate the percentage
- Python program to find Tuples with positive elements in List of tuples
- Python program to find Tuples with positive elements in a List of tuples
- List consisting of all the alternate elements in Python
- Python - Change the signs of elements of tuples in a list
- Python program to sort the elements of the Circular Linked List
- What is the percentage of the completion method?
- Find sum of frequency of given elements in the list in Python
- List frequency of elements in Python
- Calculate difference between adjacent elements in given list using Python
- How to negate the positive elements of an integer array in C#?
- Python program to sort a List according to the Length of the Elements?
- Sort a list according to the Length of the Elements in Python program
- Estimate the total income of the project with the percentage of \ncompletion method