I'm a beginner in python and having trouble with this function. I'm trying to count the values in list xs that are greater than v as well as the duplicates. I'm getting an error for line 3, should I get rid of j and just use I to represent the values in the list?
Code below that I have:
count_list = 0
for i in (xs) and j in (v):
if i > j:
count_list += 1
count_list += 0
I think this is what you are after:
def count_greater(xs,v): count = 0 for i in xs: if i >= v: count += 1 return count count_greater([12,0,20,34,0,20],3)
It returns the number of times that a value in the list is equal to or greater than the second argument (3 in the example). The value returned in this case is 4.