On 2012-09-06, Ray Jones <crawlz...@gmail.com> wrote: > > Basically it's as simple as ensuring that an array consists of integers, > and that those integers fall within a certain range. Rather than using > multiple 'if' statements, I was (am, at this point) using multiple tests > within a single 'if' statement. Nothing earth-shatteringly difficult, > but I was simply looking for a way to shorten the overall test > expression with a recursive(? is that the term) variable. No problem though. > > Thanks.
How about using a generator expression with all()? For example: >>> def isint(n): ... return int(n) == n ... >>> def isinrange(n, a, b): ... return a <= n <= b ... >>> numbers = [11, 12, 14, 15] >>> all(isint(x) and isinrange(x, 10, 20) for x in numbers) True >>> numbers[0] = 9 >>> numbers [9, 12, 14, 15] >>> all(isint(x) and isinrange(x, 10, 20) for x in numbers) False >>> numbers[0] = 14.5 >>> all(isint(x) and isinrange(x, 10, 20) for x in numbers) False Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor