Saturday, March 31, 2007

list comprehensions!

List comprehensions. I've been a fan of these for a while, but I'd like to share:

tenpercent = len(lines) / 10
testset = random.sample(lines, tenpercent)
trainingset = [line for line in lines if line not in testset]


Python makes me warm and fuzzy on the inside. Also, random.sample() is pretty sexy!

No comments: