Python program to count positive and negative numbers in a list Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share 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 Lambda expression in Python to rearrange positive and negative numbers S Shivam_k Follow Improve Article Tags : Python python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Lambda expression in Python to rearrange positive and negative numbers Given an array of positive and negative numbers, arrange them such that all negative integers appear before all the positive integers in the array. The order of appearance should be maintained. Examples: Input : arr[] = [12, 11, -13, -5, 6, -7, 5, -3, -6] Output : arr[] = [-13, -5, -7, -3, -6, 12, 1 2 min read Python | Counting sign change in list containing Positive and Negative Integers Given a list containing Positive and Negative integers, We have to find number of times the sign(Positive or Negative) changes in the list. Input: [-1, 2, 3, -4, 5, -6, 7, 8, -9, 10, -11, 12] Output:9 Explanation : Sign change from -1 to 2, ans = 1 Sign change from 3 to -4, ans = 2 Sign change from 5 min read Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix Find the number of negative numbers in a column-wise / row-wise sorted matrix M[][]. Suppose M has n rows and m columns. Example: Input: M = [-3, -2, -1, 1] [-2, 2, 3, 4] [4, 5, 7, 8] Output : 4 We have 4 negative numbers in this matrix We strongly recommend you to minimize your browser and try this 15+ min read Python | Rearrange Positive and Negative Elements Sometimes, while working with Python lists, we can have a problem in which we need to perform a sort in list. There are many variations of sorting that might be required to perform. Once such variation can be to sort elements of list, but keeping in mind, positive elements appear before negative ele 8 min read How to Perform a COUNTIF Function in Python? In this article, we will discuss how to perform a COUNTIF function in Python. COUNTIF We use this function to count the elements if the condition is satisfied. Notice that the word stands as COUNT + IF. That means we want to count the element if the condition that is provided is satisfied. Approach 4 min read Count the Number of Null Elements in a List in Python In data analysis and data processing, It's important to know about Counting the Number of Null Elements. In this article, we'll explore how to count null elements in a list in Python, along with three simple examples to illustrate the concept. Count the Number of Null Elements in a List in PythonIn 3 min read Like