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
--------------------------------------------------------
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor