Re: Problem with list.insert



Some people in the room told I am kidding, but I learnt Python from
Python docs which gives examples like these,
But I write explicit comments,
an excerpt from python docs:
# Measure some strings:
.... a = ['cat', 'window', 'defenestrate']
for x in a:
.... print x, len(x)
....
cat 3
window 6
defenestrate 12
But well, if you are suggesting improvement I'll surely listen.

The outputs are given in Hindi, it is a dictionary look up program,
the matching words are in Hindi, you may leave aside them.
How to debug the result string is to see the words which are in
English as the group page does not take italics so I am putting one
asterisk* after it
NO PROBLEM:
INPUT:
he has come
OUTPUT IS
उओह/ उन्होने रहेसाक्ता २.यात्राकरना
PROBLEM:
INPUT:
(i) Lincoln* has come
OUTPUT IS:
रहेसाक्ता २.यात्राकरना lincoln*
lincoln lincoln* रहेसाक्ता २.यात्राकरना lincoln
lincoln lincoln* lincoln* रहेसाक्ता २.यात्राकरना lincoln
….and increasing the number and seems a never ending process.
MY EXPEPECTED STRING IS:
lincoln रहेसाक्ता २.यात्राकरना lincoln^
The latter places marked^ I am editing don't worry for that,
though MY FINAL EXPECTED STRING IS:
lincoln रहेसाक्ता २.यात्राकरना
Best Regards,
Subhabrata.



Marc 'BlackJack' Rintsch wrote:
On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:

import re
def wordchecker1(n):
# INPUTTING STRING
a1=raw_input("PRINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
#CONVERTING TO LOWER CASE
a2=a1.lower()
#CONVERTING INTO LIST
a3=a2.split()
#DICTIONARY
a4=open("/python25/Changedict3.txt","r") a5=a4.read()
a6=a5.split()
found=[]
not_found=[]
#SEARCHING DICTIONARY
for x in a3:
a7="\n"
a8=a7+x
if a8 in a5:
a9=a5.index(a8)
a10=a5[a9:]
a11=re.search("\xe0.*?\n",a10)
a12=a11.group()
a13=a12[:-1]
found.append(a13)
elif a8 not in a5:
a14=x
not_found.append(a14)
else:
print "Error"
found.extend(not_found)
# THE OUTPUT
print "OUTPUT STRING IS"
a15=(' '.join(found))
#THE OUTPUT STRING
print a15
# SPLITTING OUTPUT STRING IN WORDS
a16=a15.split()
#TAKING OUT THE WORD FROM OUTPUT STRING for word in a16:
#MATCHING WITH GIVEN STRING
a17=a2.find(word)
if a17>-1:
print "The word is found in the Source String"
a18=a3.index(word)
a19=a3[a18]
print a19
#INSERTING IN THE LIST OF TARGET STRING
a20=a16.insert(a18,a19)
print a16
a21=(" ".join(a16))
print a21

a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
and use *meaningful* names instead!

Could you describe them problem better, with sample inputs and expected
outputs. There must be a better way that that unreadable mess above.

Ciao,
Marc 'BlackJack' Rintsch
.



Relevant Pages

  • Re: formattting numbers
    ... use the Mid statement and "stuff" your data strings into an output string and then assign that output string to your TextBox. ... Note the declaration of the OutString variable... ... Const ColumnOneStart As Long = 2 ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem with list.insert
    ... Python docs which gives examples like these, ... MY EXPEPECTED STRING IS: ... print "OUTPUT STRING IS" ...
    (comp.lang.python)
  • Re: Writing Custom Aggregate Functions
    ... and loop through the records building up the output string. ... textbox in the group footer of my report using the syntax: ...
    (microsoft.public.access.reports)
  • Re: formattting numbers
    ... I wouldn't use concatenations of formatted text to do this; rather, I would use the Mid statement and "stuff" your data strings into an output string and then assign that output string to your TextBox. ... Note the declaration of the OutString variable... ... Const ColumnOneStart As Long = 2 ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem with list.insert
    ... #CONVERTING TO LOWER CASE ... print "OUTPUT STRING IS" ...
    (comp.lang.python)