[Tutor] How can I make this run faster?

Emad Nawfal (عمـ نوفل ـاد) emadnawfal at gmail.com
Mon Dec 21 17:40:01 CET 2009


Dear Tutors,
The purpose of this script is to see how many vocalized forms map to a
single consonantal form. For example, the form "fn" could be fan, fin, fun.

The input is a large list (taken from a file) that has ordinary words. The
script creates a devocalized list, then compares the two lists.

The problem: It takes over an hour to process 1 file. The average file size
is 400,000 words.

Question: How can I make it run faster? I have a large number of files.

Note: I'm not a programmer, so please avoid very technical terms.

Thank you in anticipation.





def devocalize(word):
    vowels = "aiou"
    return "".join([letter for letter in word if letter not in vowels])


vowelled = ['him', 'ham', 'hum', 'fun', 'fan'] # input, usually a large list
of around 500,000 items

vowelled = set(vowelled)

unvowelled = set([devocalize(word) for word in vowelled])


for lex in unvowelled:
    d = {}
    d[lex] = [word for word in vowelled if devocalize(word) == lex]

    print lex, " ".join(d[lex])

-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091221/08dc14a6/attachment.htm>


More information about the Tutor mailing list