The sorting approach sounds reasonable. We might even couple it with
itertools.groupby() to get the consecutive grouping done for us.
https://docs.python.org/2/library/itertools.html#itertools.groupby
For example, the following demonstrates that there's a lot that the
library will do for us that should apply directly to Mark's problem:
#########################################
import itertools
import random
def firstTwoLetters(s): return s[:2]
grouped = itertools.groupby(
sorted(open('/usr/share/dict/words')),
key=firstTwoLetters)
for k, g in grouped:
print k, list(g)[:5]
#########################################
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor