Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread Peter Pearson
On Tue, 11 Dec 2012 16:39:27 +, duncan smith wrote: [snip] > >>> alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > >>> key = "XPMGTDHLYONZBWEARKJUFSCIQV" > >>> mapping = {} > >>> for i, ch in enumerate(alpha): > mapping[ch] = key[i] mapping = dict(zip(alpha, key)) -- To email me, substitute nowhe

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread Tim Delaney
On 12 December 2012 07:52, Ross Ridge wrote: > John Gordon wrote: > > def encode(plain): > > '''Return a substituted version of the plain text.''' > > encoded = '' > > for ch in plain: > >encoded += key[alpha.index(ch)] > > return encoded > > Terry Reedy wrote: > >The tu

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread Ross Ridge
John Gordon wrote: > def encode(plain): > '''Return a substituted version of the plain text.''' > encoded = '' > for ch in plain: >encoded += key[alpha.index(ch)] > return encoded Terry Reedy wrote: >The turns an O(n) problem into a slow O(n*n) solution. Much better to >

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread Terry Reedy
On 12/10/2012 5:59 PM, John Gordon wrote: def encode(plain): '''Return a substituted version of the plain text.''' encoded = '' for ch in plain: encoded += key[alpha.index(ch)] return encoded The turns an O(n) problem into a slow O(n*n) solution. Much better to build a

Re: String manipulation in python..NEED HELP!!!!

2012-12-11 Thread duncan smith
On 10/12/12 22:38, qbai...@ihets.org wrote: I need help with a program i am doing. it is a cryptography program. i am given a regular alphabet and a key. i need to use the user input and use the regular alphabet and use the corresponding letter in the key and that becomes the new letter. i hav

Re: String manipulation in python..NEED HELP!!!!

2012-12-10 Thread Chris Angelico
On Tue, Dec 11, 2012 at 9:38 AM, wrote: > I need help with a program i am doing. it is a cryptography program. i am > given a regular alphabet and a key. i need to use the user input and use the > regular alphabet and use the corresponding letter in the key and that becomes > the new letter. i

Re: String manipulation in python..NEED HELP!!!!

2012-12-10 Thread Vlastimil Brom
2012/12/10 : > I need help with a program i am doing. it is a cryptography program. i am > given a regular alphabet and a key. i need to use the user input and use the > regular alphabet and use the corresponding letter in the key and that becomes > the new letter. i have the basic code but nee

Re: String manipulation in python..NEED HELP!!!!

2012-12-10 Thread John Gordon
In qbai...@ihets.org writes: > """ crypto.py > Implements a simple substitution cypher > """ > alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > key = "XPMGTDHLYONZBWEARKJUFSCIQV" > def main(): > keepGoing = True > while keepGoing: > response = menu() > if response == "1": > plain

Re: string manipulation.

2010-07-27 Thread Mark Tolonen
"gerardob" wrote in message news:29276755.p...@talk.nabble.com... I am trying to read an xml using minidom from python library xml.dom This is the xml file: - AB 100 2 -- This is the python code:

Re: string manipulation.

2010-07-27 Thread Neil Cerutti
On 2010-07-27, gerardob wrote: > > I am trying to read an xml using minidom from python library xml.dom > > This is the xml file: > - > > > > AB > 100 > > 2 > >

Re: String manipulation questions

2008-04-09 Thread goldtech
snip... > >for counter, line in enumerate(fileIN): >newline = line.replace(oldstring, newstring) >if newline != line: >print 'match at line', counter+1 >fileOUT.write(newline) "enumerate" - haven't seen that before. Nice! Thanks -- http://mail.python.org/m

Re: String manipulation questions

2008-04-09 Thread Duncan Booth
goldtech <[EMAIL PROTECTED]> wrote: > Question1: The replace method - If a string does not have the target > replacement "newstring", then newline equals oldstring? Ie. oldstring > is not changed in any way? Seems to be what I observe but just want to > confirm this. Yes. > > Question2: I'm us

Re: String manipulation

2007-04-05 Thread Alexander Schmolck
[EMAIL PROTECTED] writes: > On 4 Apr, 21:47, Alexander Schmolck <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] writes: > > > Thank you very much, your code works perfectly! > > > > One thing I forgot: you might want to make the whitespace handling a bit > > more > > robust/general e.g. by using

Re: String manipulation

2007-04-05 Thread marco . minerva
On 4 Apr, 21:47, Alexander Schmolck <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Thank you very much, your code works perfectly! > > One thing I forgot: you might want to make the whitespace handling a bit more > robust/general e.g. by using something along the lines of > > set_phra

Re: String manipulation

2007-04-04 Thread Alexander Schmolck
[EMAIL PROTECTED] writes: > Thank you very much, your code works perfectly! One thing I forgot: you might want to make the whitespace handling a bit more robust/general e.g. by using something along the lines of set_phrase.replace(' ', r'\w+') 'as -- http://mail.python.org/mailman/listinfo/p

Re: String manipulation

2007-04-04 Thread marco . minerva
On 4 Apr, 17:39, Alexander Schmolck <[EMAIL PROTECTED]> wrote: > All the code is untested, but should give you the idea. > > > > > > [EMAIL PROTECTED] writes: > > Hi all! > > > I have a file in which there are some expressions such as "kindest > > regard" and "yours sincerely". I must create a phyt

Re: String manipulation

2007-04-04 Thread Alexander Schmolck
Alexander Schmolck <[EMAIL PROTECTED]> writes: > That doesn't work. What about "kindest\nregard"? I think you're best of > reading the whole file in (don't forget to close the files, BTW). I should have written "that may not always work, depending of whether the set phrases you're interested in c

Re: String manipulation

2007-04-04 Thread Alexander Schmolck
All the code is untested, but should give you the idea. [EMAIL PROTECTED] writes: > Hi all! > > I have a file in which there are some expressions such as "kindest > regard" and "yours sincerely". I must create a phyton script that > checks if a text contains one or more of these expressions an

Re: String Manipulation Help!

2006-01-28 Thread Paul McGuire
"Richard Schneiderman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I really enjoyed your article. I will try to understand this. > Will you be doing more of this in the future with more complicated examples? > I'm giving two presentations at PyCon at the end of February, so I thin

Re: String Manipulation Help!

2006-01-28 Thread Richard Schneiderman
I really enjoyed your article. I will try to understand this. Will you be doing more of this in the future with more complicated examples? Paul McGuire wrote: > "Dave" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> OK, I'm stumped. >> >> I'm trying to find newline characters (

Re: String Manipulation Help!

2006-01-28 Thread Paul McGuire
"Dave" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > OK, I'm stumped. > > I'm trying to find newline characters (\n, specifically) that are NOT > in comments. > > So, for example (where "<-" = a newline character): > == > 1: <- > 2: /*<- > 3:

Re: String Manipulation Help!

2006-01-28 Thread Dave
This is great, thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: String Manipulation Help!

2006-01-28 Thread Kirk McDonald
Dave wrote: > OK, I'm stumped. > > I'm trying to find newline characters (\n, specifically) that are NOT > in comments. > > So, for example (where "<-" = a newline character): > == > 1: <- > 2: /*<- > 3: --<- > 4: comment<- > 5:

Re: String Manipulation

2005-07-13 Thread Josef Meile
Hi, > for punctuation in punctuations: > line=line.replace(punctuation,'') I would use maketrans or even a regex instead. However, If you care about speed, it is well known that in some cases regex take more time than multiple replaces. Even the maketrans could take more time (I don't

Re: String Manipulation

2005-07-13 Thread Bill Mill
On 13 Jul 2005 07:49:02 -0700, Michael Jordan <[EMAIL PROTECTED]> wrote: > hey, i have this huge text file and i need to go through and remove all > punctuation and every instance of the phrase "fruitloops=$" where $ is > any number 0-100" um, and yeah this is homework but i've tried to no > avail

Re: String Manipulation

2005-07-13 Thread Larry Bates
Use .replace function to replace punctuation (you didn't say exactly what that means but just to get you started): # # Extend this list as needed # punctuations=',.;:()' # # Open input and output files # ifp=open(inputfilename,'r') ofp=open(outputfilename,'w') # # Strip out the punctuation charact

Re: String manipulation

2005-04-14 Thread Terry Reedy
"vincent wehren" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Nicholas Graham" > | Any suggestions? > Take a look at the built-in functions ord() and chr() > -- Chapter 2.1 of the manual. And more generally, read all of Chap.2 of the Library Reference on builtin functions an

Re: String manipulation

2005-04-13 Thread vincent wehren
"Nicholas Graham" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] | | I'm writing a program that requires some string manipulations. Let's say | I have a string | | s='x' | | Now, the ascii code for 'x' is 0x78. I want to be able to perform | operations on this number, and prin