En Sat, 21 Feb 2009 01:14:02 -0200, odeits <ode...@gmail.com> escribió:
On Feb 15, 11:31 pm, odeits <ode...@gmail.com> wrote:

It seems what you are actually testing for is if the intersection of
the two sets is not empty where the first set is the characters in
your word and the second set is the characters in your defined string.

To expand on what I was saying I thought i should provide a code
snippet:

WORD = 'g' * 100
WORD2 = 'g' * 50 + 'U'
VOWELS = 'aeiouAEIOU'
BIGWORD = 'g' * 10000 + 'U'

def set_test(vowels, word):

    vowels = set( iter(vowels))
    letters = set( iter(word) )

    if letters & vowels:
        return True
    else:
        return False

with python 2.5 I got 1.30 usec/pass against the BIGWORD

You could make it slightly faster by removing the iter() call: letters = set(word)
And (if vowels are really constant) you could pre-build the vowels set.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to