19. Write a python function to count the negative number in the list a and list b.
The output is:
list_a = [6, 2, 7, -8, -5]
list_b = [3, 2, 7, 9, -5, 1]
Expected Answer:
Count of negative number: [2]
Count of negative number: [1]
Sample Answer:
def count_neg(nums): if not nums: return [] return [len([n for n in nums if n < 0])] list_a = [6, 2, 7, -8, -5] list_b = [3, 2, 7, 9, -5, 1] print("Count of negative number:", count_neg(list_a)) print("Count of negative number:", count_neg(list_b))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)