1
2
3
4
from itertools import groupby
import doctest

...

Python On Count word occurrences in a...

by Leif Ryge, October 31, 2008 20:37

Here is another version whi...

264124475f095b65634c53da3380b88d Talk
1
2
3
4
def mk_index(seq):
    """Index a sequence
    >>> sorted(mk_index("abcba").items())
...

Python On Count word occurrences in a...

by Leif Ryge, October 31, 2008 19:58

This prints not only the co...

264124475f095b65634c53da3380b88d Talk

Python On Computing permutations with...

by Leif Ryge, October 31, 2008 06:55 Star_fullStar_fullStar_fullStar_fullStar_full

Answering my own question: ...

264124475f095b65634c53da3380b88d Talk
1
2
3
idiom_A = lambda x,y,z: (x and [y] or [z])[0]
idiom_B = lambda x,y,z: (z, y)[x]
idiom_C = lambda x,y,z: y if x else z # introduced in Python 2.5

Python On Computing permutations with...

by Leif Ryge, October 30, 2008 20:23

Thanks! I was actually unaw...

264124475f095b65634c53da3380b88d Talk

Python On Permutation of values

by Leif Ryge, October 22, 2008 04:55

[edit: redacted, sorry]

264124475f095b65634c53da3380b88d Talk
1
2
3
4
#!/usr/bin/python2.5
def permute(li):
    """Generate all permutations of a sequence
...

Python Computing permutations with...

by Leif Ryge, October 22, 2008 04:16, 6 refactorings, tagged with generator, permutations, permutate, recursion

I suspect there is a better...

264124475f095b65634c53da3380b88d Talk