I was looking at a way to implement Ruby's upto method in python. I came up with the code below... three years ago, I would never have thought of list comprehension, today it seems second nature. This may be totally un-Pythonic, but I thought it was kind of clever. Man, for some reason, I feel like being rude and lofty acting :)
low_odds = [1,3,5,7,9] # make a list containing 10 - 98 evens only big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 == 0 and x >8] low_evens = [2,4,6,8] # make a list containing 11 - 99 odds only big_odds = [x for x in list(xrange(100)) if x % 2 != 0 and x >9] y = 8 if y in low_evens: ok_numbers = low_odds + big_evens + [x for x in low_evens if x <= y] -- http://mail.python.org/mailman/listinfo/python-list