By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

Re: Problem with list.insert

P: n/a
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
Aug 28 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Aug 28 '08 #2

P: n/a
SUBHABRATA schrieb:
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.
Please! Just because a tiny 3 lines example involing just *one* list
doesn't give that a long & speaking name does not mean
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
Aug 28 '08 #3

P: n/a
Diez B. Roggisch schrieb:
SUBHABRATA schrieb:
>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.

Please! Just because a tiny 3 lines example involing just *one* list
doesn't give that a long & speaking name does not mean
discard my last post - I accidentially pressed submit to early.

Numbering variable names surely is *not* found in any python example.
Short names, as the examples are clear & don't require more meaningful
names occur, yes. But nowhere you will find 2-figure enumerations.

Each book or tutorial about programming will teach you to use meaningful
variables for your program.

As far as your explanation goes: there is *nothing* to be understood
from a bunch of questionmarks + sometimes "lincoln" spread in between is
not really helping.

This is most probably not your fault, as somehow the hindi get's twisted
to the questionmarks - however, I suggest you provide an example where
the hindi is replaced with english words (translations, or placeholders)
- otherwise, you won't be understood, and can't be helped.

Diez
Aug 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.