the python way?

Raymond Hettinger python at rcn.com
Tue Jun 7 03:02:19 EDT 2005


import random
from itertools import ifilter, ifilterfalse

def reinterpolate(word):

    word = list(word)
    random.shuffle(word)

    isvowel = dict.fromkeys('aeiouy').has_key
    vowels = ifilterfalse(isvowel, word)
    consonants = ifilter(isvowel, word)

    result = []
    for v, c in map(None, vowels, consonants):
        if c:
            result.append(c)
        if v:
            result.append(v)
    return ''.join(result)

print reinterpolate("encyclopedias")




More information about the Python-list mailing list