473,573 Members | 2,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Problem with list.insert

On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
import re
def wordchecker1(n) :
# INPUTTING STRING
a1=raw_input("P RINT 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(a1 3)
elif a8 not in a5:
a14=x
not_found.appen d(a14)
else:
print "Error"
found.extend(no t_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(wor d)
if a17>-1:
print "The word is found in the Source String"
a18=a3.index(wo rd)
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
3 1793
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("P RINT 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(a1 3)
elif a8 not in a5:
a14=x
not_found.appen d(a14)
else:
print "Error"
found.extend(no t_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(wor d)
if a17>-1:
print "The word is found in the Source String"
a18=a3.index(wo rd)
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
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("P RINT 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(a1 3)
elif a8 not in a5:
a14=x
not_found.appen d(a14)
else:
print "Error"
found.extend(no t_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(wor d)
if a17>-1:
print "The word is found in the Source String"
a18=a3.index(wo rd)
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22035
by: N | last post by:
Hi, I would like to parse out each value that is seperated by a comma in a field and use that value to join to another table. What would be the easiest way to do so without having to write a function or routine ? EX. Table AAA COL1 COL2
7
631
by: Shawn Windle | last post by:
----begin node.h-------- #ifndef NODE_H #define NODE_H #include <iostream> //NULL using namespace std; class node {
6
9129
by: dam_fool_2003 | last post by:
Hai, I thank those who helped me to create a single linked list with int type. Now I wanted to try out for a void* type. Below is the code: #include<stdlib.h> #include<stdio.h> #include<string.h> #include<stddef.h> struct node
2
2428
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I...
13
2080
by: B. Williams | last post by:
I have written some code to accept input and place this input at the beginning or end of a list, but I need assistance including a class so that it will allow input of a phone number that is properly formatted. I'll post my code below. Thanks in advance. This is the code for the linked list. It tests using int's and string's. #ifndef...
9
2828
by: william | last post by:
When implementing Linked list, stack, or trees, we always use pointers to 'link' the nodes. And every node is always defined as: struct node { type data; //data this node contains ... node * nPtr; //the next node's pointer }
1
1621
by: dabbakal | last post by:
Hello, am a new member and this is my first posting. C++ is the first progrsaming language am taking and is just for 3 months. Having benefited from lot of posting i decided to join. But currently am trying to solve an exercise and it is proven difficult for me. I have written a program in c++ in linked list but am facing two problems. (1) when...
13
2943
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
6
3254
by: APEJMAN | last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result I post the code here I dont wanne bother you, but if any one of you have time to read my program I appriciate it. the program suppose to print a message on the screen #include <iostream> #include <string>
17
1423
by: yang2006 | last post by:
I'm using Dev-c. #include <stdio.h> #include <stdlib.h> #include <string.h> class Node { friend class List;
0
7753
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
8187
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7751
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8045
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5275
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3714
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1280
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.