[Tutor] creating a range above & below a given number
Alan Gauld
alan.gauld at btinternet.com
Sun Jun 7 00:57:06 CEST 2009
"Gonzalo Garcia-Perate" <gonzillaaa at gmail.com> wrote
> Hello tutor, What's the simplest way of creating a list with a range
> of numbers above and below a given number?
> ...
> this works fine, but is there a simpler way of doing it? a one liner? :)
I'd probably use a list comprehesion:
L = [n for n in range(lower, upper+!) if n < median-threshold or n >
medianthreshold]
eg:
>>> [n for n in range(5,21) if n < 10 or n > 16]
[5, 6, 7, 8, 9, 17, 18, 19, 20]
>>>
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list