[docs] Example for itertools.groupby()
jesse at wefu.org
Wed Oct 13 10:55:16 CEST 2010
I noticed that itertools.groupby() lacks an example of it's use. (as
shown in the table at the top of:
http://docs.python.org/library/itertools.html ). Here's one quick one I
[''.join([z for z in y]) for (x,y) in itertools.groupby("What's up,
brown cow?",str.isalpha) if x]
will print the words in the string.
In a form more matching the existing examples:
itertools.groupby("Hello, world!",str.isalpha) ->
(True, "Hello"), (False, ", "), (True, "world"), (False, "!")
Feel free to use it if you wish. I renounce any copyright interests I
may have in it (if it's even long enough to avoid "de minimis").
More information about the docs