Reputation: 67
I have written this function trying to get it to return true or false in terms of the following condition, however I get this result when testing it:
>>> has_gt([2,3,4], 2)
False
def has_gt(nums, n):
"""Return True iff nums contains at least one number bigger than n.
has_gt(list<number>, number) -> boolean
"""
for i in (nums, n):
if i in nums > n:
return True
else:
return False
Upvotes: 1
Views: 7348
Reputation: 117856
def has_gt(myList, value):
return any(i > value for i in myList)
>>> has_gt([2,3,4], 3)
True
>>> has_gt([1,2,3], 7)
False
Using a for loop
def has_gt(myList, value):
for i in myList:
if i > value:
return True
return False
Upvotes: 3