"Gonzalo Garcia-Perate" <[email protected]> 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/
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor