Python program to count positive and negative numbers in a list Last Updated : 24 Jun, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will explore various methods to count positive and negative numbers in a list. The simplest way to do this is by using a loop. This method counts the positive and negative numbers in a list by iterating through each element using for loop. Python a = [10, -20, 30, -40, 50, -60, 0] # Counts the positive numbers pos = 0 # Counts the negative numbers neg = 0 # Iterate through the list for n in a: if n > 0: pos += 1 elif n < 0: neg += 1 print(pos) print(neg) Output3 3 Let's explore other different method:Table of ContentUsing List ComprehensionUsing filter() FunctionUsing filter() Functionfilter() function can be used to filter positive and negative numbers and we can count them using len(). It is better than a manual loop since it avoids the explicit creation of new lists during iteration. Python a = [10, -20, 30, -40, 50, -60, 0] # Count positive numbers using filter pos = len(list(filter(lambda x: x > 0, a))) # Count negative numbers using filter neg = len(list(filter(lambda x: x < 0, a))) print(pos) print(neg) Output3 3 Using List ComprehensionList comprehension provides a more concise way to count positive and negative numbers. It iterate through the list and create new lists based on conditions. Python a = [10, -20, 30, -40, 50, -60, 0] # Count positive numbers pos = len([n for n in a if n > 0]) # Count negative numbers neg = len([n for n in a if n < 0]) print(pos) print(neg) Output3 3 Comment More infoAdvertise with us Next Article Python program to count positive and negative numbers in a list S Shivam_k Follow Improve Article Tags : Python Python Programs Computer Science Fundamentals DSA python-list Python list-programs +2 More Practice Tags : pythonpython-list Similar Reads Python program to print negative numbers in a list In Python, itâs often necessary to find and print negative numbers from a list. In this article we will explore various approches to print negative numbers in a list. The most basic method for printing negative numbers is to use a for loop to iterate through the list and check each element.Pythona = 2 min read Python Program to Count Even and Odd Numbers in a List In Python working with lists is a common task and one of the frequent operations is counting how many even and odd numbers are present in a given list. The collections.Counter method is the most efficient for large datasets, followed by the filter() and lambda approach for clean and compact code. Us 4 min read Python Program to find Sum of Negative, Positive Even and Positive Odd numbers in a List Given a list. The task is to find the sum of Negative, Positive Even, and Positive Odd numbers present in the List. Examples: Input: -7 5 60 -34 1 Output: Sum of negative numbers is -41 Sum of even positive numbers is 60 Sum of odd positive numbers is 6 Input: 1 -1 50 -2 0 -3 Output: Sum of negative 7 min read Python program to print positive numbers in a list In this article, we will explore various methods to o print positive numbers in a list. The simplest way to do is by using for loop function. Using LoopThe most basic method for printing positive numbers is to use a for loop to iterate through the list and check each element.Pythona = [-10, 15, 0, 2 1 min read Python program to count Even and Odd numbers in a Dictionary Given a python dictionary, the task is to count even and odd numbers present in the dictionary. Examples: Input : {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e' : 5}Output : Even = 2, odd = 3Input : {'x': 4, 'y':9, 'z':16}Output : Even = 2, odd = 1 Approach using values() Function: Traverse the dictionary and 3 min read Like