the itertools and collections modules firstsuppose is list of zeros and onesand we want to find out how long the longest run of ones is we can do that in one line using groupbymax([len(list(group)for key,group in groupby(lif key== ]secondsuppose we have function called easter that returns the date of easter in given year the following code will produce histogram of which dates occur most often from to [easter(yfor in range( , ) sort(for key,group in groupby( )print(key''''*(len(list(group)) miscellaneous things from itertools chain the chain function chains iterators together into one big iterator for exampleif you have three listslmand and want to print out all the elements of eachone after anotheryou can do the followingfor in chain( , , )print(ias another examplein section we used list comprehensions to flatten list of liststhat is to return list of all the elements in the lists here is another way to do that using chainl [[ , , ][ , , ][ , , ]list(chain(*tuple( ))[ count the function count(behaves like range(it takes an optional argument so that count(xbehaves like range( ,cycle the cycle function cycles over the elements of the iterator continuously when it gets to the endit starts over at the beginningand keeps doing this forever the following simple example prints the numbers through continuously until the user enters an ' 'for in cycle(range( )) input'keep goingy or 'if =' 'break print(xmore about iterators there are number of other functions in the itertools module see the python documentation [ for more it has nice table summarizing what the various functions do