Hi Danny, Marc, Peter and Alex, Thanks for the responses! Very much appreciated.
I will take these pointers and see what I can pull together. Thanks again to all of you for taking the time to help! Cheers, Mark On Tue, Jun 24, 2014 at 4:39 PM, Danny Yoo <[email protected]> wrote: > 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 > -- Mark S. Murphy Alumnus Department of Geography [email protected] 951-252-4325
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
