How can I use python itertools.groupby() to group a list of strings by their first character?

Posted by Adam Z. on Stack Overflow See other posts from Stack Overflow or by Adam Z.
Published on 2010-03-18T17:25:27Z Indexed on 2010/03/18 17:51 UTC
Read the original article Hit count: 171

Filed under:
|
|

I have a list of strings similar to this list:

tags = ('apples', 'apricots', 'oranges', 'pears', 'peaches')

How should I go about grouping this list by the first character in each string using itertools.groupby()? How should I supply the 'key' argument required by itertools.groupby()?

© Stack Overflow or respective owner

Related posts about python

Related posts about itertools