Determining whether a variable is less/greater than a range.

eric eric at ericaro.net
Mon Dec 8 05:55:56 EST 2008


On Dec 8, 11:44 am, "simonharrison... at googlemail.com"
<simonharrison... at googlemail.com> wrote:
> Hi. I'm having another go at learning Python so I'll probably be
> asking a few basic questions. Here is the first one.
>
> a = list(range(10, 21)
>
> b = 9
>
> c = 21
>
> How can I find out if b and c have values less or more than the values
> in list a?
>
> Thanks.


what about:
a = list(range(10, 21))


def compare(value, list):
    m,M = min(list), max(list)
    return value>=m, value<=M

b = 9
c = 21

print compare(b,a)
print compare(c,a)

for i in range (8, 25):
    print i, compare(i, a)


"""
(False, True)
(True, False)
8 (False, True)
9 (False, True)
10 (True, True)
11 (True, True)
12 (True, True)
13 (True, True)
14 (True, True)
15 (True, True)
16 (True, True)
17 (True, True)
18 (True, True)
19 (True, True)
20 (True, True)
21 (True, False)
22 (True, False)
23 (True, False)
24 (True, False)
"""

it helps?



More information about the Python-list mailing list