[BangPypers] if not with comparision statement in python
Anand Chitipothu
anandology at gmail.com
Mon Aug 1 12:47:31 CEST 2011
2011/8/1 Dhananjay Nene <dhananjay.nene at gmail.com>:
> On Sat, Jul 30, 2011 at 2:15 PM, Asif Jamadar <asif.jamadar at rezayat.net> wrote:
>> What if I have two lists for both minimum and maximum values
>>
>> Minimum Maximum
>> 0 10
>> 11 20
>> 21 30
>> 31 40
>>
>>
>> Now how should I check if actual result is not laying between above ranges
>>
>> if not minimum<=actual_result and not maximum>=actual_result:
>>
>> Any suggestions?
>
> def in_range(number) :
> return any(map(lambda (x,y) : x <= number <= y,
> ((0,10),(11,20), (21,30), (31,40))))
How about this?
def in_range(number, min_max_pairs):
return any(x <= number <=y for x, y in min_max_pairs)
List comprehensions and generation expressions are usually more
readable and expressive than using map.
Anand
More information about the BangPypers
mailing list