Anonymous - 2007-10-31 09:56:43
You can knock off a list traversal:
def cluster_by(f, lst): d = dict() for x in lst: key = f(x) d.setdefault(key,[]).append(x) return d.values()
And use a generator instead of a list comprehension:
clustered = cluster_by(normalize,((x,y) for x in states for y in states))
formatting is with Textile syntax. Comments are not displayed until they are approved by a moderator. Moderators will not approve unless the comment contributes value to the discussion.
Anonymous - 2007-10-31 09:56:43
You can knock off a list traversal:
def cluster_by(f, lst):
d = dict()
for x in lst:
key = f(x)
d.setdefault(key,[]).append(x)
return d.values()
And use a generator instead of a list comprehension:
clustered = cluster_by(normalize,((x,y) for x in states for y in states))