472,127 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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:

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.

Aug 28 '08 #1
0 745

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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.