def changeWordSize ( words, inSize, outSize ):
    """
    >>> list( changeWordSize( [255, 18], 8, 1 ) )
...

Python changeWordSize

by Leif Ryge, July 18, 2011 18:31, No refactoring, tagged with generator, generators, binary, bitwise, bitshift, ordinal, words

Generator which transforms ...

264124475f095b65634c53da3380b88d Talk
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
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
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
#!/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 recursion, generator, permutations, permutate

I suspect there is a better...

264124475f095b65634c53da3380b88d Talk