2011/8/1 Dhananjay Nene <dhananjay.n...@gmail.com>:
> On Sat, Jul 30, 2011 at 2:15 PM, Asif Jamadar <asif.jama...@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
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to