My goal is to create a function that would check whether a number is in a given range.
So, I've created a function range_check() that takes three arguments - number, low and high. I've also created 4 test cases that are stored as tuples. The first three test cases are true, the last one is false.
def range_check(num, low, high):
return low <= num <= high
test_values = [(2, 1, 4), (5, 2, 7), (3, 1, 10), (3, 4, 5)]
for test_case in test_values:
print(range_check(test_case[0], test_case[1], test_case[2]))
Since I've lately discovered what lambda is and how to use it (I'm still new to Python and programming in general), I wanted to try to solve this using lambda and map (or filter could also be used here, I guess)
test_values = [(2, 1, 4), (5, 2, 7), (3, 1, 10), (3, 4, 5)]
print(list(map(lambda num, low, high: low <= num <= high, test_values)))
However, this gives an error - lambda is missing 2 required arguments - low and high.
Is there any way how I can insert a tuple of arguments into a function or lambda like this?
The only thing that I came up with is to make lists of numbers, lows and highs.
nums = [2, 5, 3, 3]
lows = [1, 2, 1, 4]
highs = [4, 7, 10, 5]
print(list(map(lambda num, low, high: low <= num <= high, nums, lows, highs)))
But this doesn't seem to be much easier and may be hard to understand later, in my opinion.
Thanks a lot in advance for any help or ideas.