Determining whether a variable is less/greater than a range.
Peter Otten
__peter__ at web.de
Mon Dec 8 06:05:47 EST 2008
simonharrison.uk 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?
>>> a = range(10, 21)
>>> b = 9
>>> c = 21
Are there any items in a that are less than b or greater than c?
>>> any(x<b or x>c for x in a)
False
No. Are there any items in a that are greater than b?
>>> any(x>b for x in a)
True
Yes.
Peter
More information about the Python-list
mailing list