469,602 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Re: Problem with list.insert

Subhabrata, it's very difficult for me to understand what your short
program has to do, or what you say. I think that formatting and code
style are important.

So I suggest you to give meaningful names to all your variable names,
to remove unused variables (like n), to add blank likes here and there
to separate logically separated parts of your program, or even better
to split it into functions. You can remove some intermediate function,
coalescing few logically related operations into a line, you can put
spaces around operators like = and after a commas, you can show an
usage example in English, so people can understand what the program is
supposed to to, you can avoid joining and then splitting strings
again, remove useless () around certain things.

This is a possible re-write of the first part of your code, it's not
exactly equal...
def input_words():
input_message = "Print one English sentence for dictionary check:
"
return raw_input(input_message).lower().split()
def load_dictionary():
return set(line.rstrip() for line in open("words.txt"))
def dictionary_search(dictionary, words):
found = []
not_found = []

for word in words:
if word in dictionary:
found.append(word)
else:
not_found.append(word)

return found + not_found
inwords = input_words()
dictionary = load_dictionary()
print dictionary_search(dictionary, inwords)
It's far from perfect, but you can use it as starting point for a
rewrite of your whole program.

Bye,
bearophile
Aug 28 '08 #1
0 670

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Shawn Windle | last post: by
6 posts views Thread by dam_fool_2003 | last post: by
13 posts views Thread by B. Williams | last post: by
1 post views Thread by dabbakal | last post: by
6 posts views Thread by APEJMAN | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.