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

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 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 tjre...@udel.edu wrote: The turns an O(n) problem into a slow O(n*n) solution. Much

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

2012-12-11 Thread Tim Delaney
On 12 December 2012 07:52, Ross Ridge rri...@csclub.uwaterloo.ca 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

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 nowhere-spamcop,

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

2012-12-10 Thread qbailey
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 need help with how to

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

2012-12-10 Thread John Gordon
In d6779e35-32b8-417a-abf9-72454573b...@googlegroups.com qbai...@ihets.org writes: crypto.py Implements a simple substitution cypher alpha = ABCDEFGHIJKLMNOPQRSTUVWXYZ key = XPMGTDHLYONZBWEARKJUFSCIQV def main(): keepGoing = True while keepGoing: response = menu()

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

2012-12-10 Thread Vlastimil Brom
2012/12/10 qbai...@ihets.org: 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

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

2012-12-10 Thread Chris Angelico
On Tue, Dec 11, 2012 at 9:38 AM, 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

string manipulation.

2010-07-27 Thread gerardob
want) but instead it is a string that has length of 8 and it seems it include the tabs and/or other things. How can i get the string AB without the other stuff? Thanks. -- View this message in context: http://old.nabble.com/string-manipulation.-tp29276755p29276755.html Sent from

Re: string manipulation.

2010-07-27 Thread Neil Cerutti
On 2010-07-27, gerardob gberbeg...@gmail.com wrote: I am trying to read an xml using minidom from python library xml.dom This is the xml file: - rm_structure resources resource AB Capacity100/Capacity

Re: string manipulation.

2010-07-27 Thread Mark Tolonen
gerardob gberbeg...@gmail.com 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: - rm_structure resources resource AB Capacity100/Capacity NumberVirtualClasses 2

String manipulation using RE

2008-10-26 Thread aditya shukla
Hello folks, i have a string eg (((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4) now i have to convert this string to (((A:1,B:1):2,C:3):1,((E:1,F:1):1,D:2):2) So i used the logic eg. taking the substring 1):3 and converting it to 1):2(3-1=2) so on for all the similar substrings.But i am not able to

String manipulation questions

2008-04-09 Thread goldtech
Hi, Replacing strings in a text (likely an XML) file. Some newbie questions... ... while line: counter=counter+1 if line.find(newstring) != -1: print 'match at line'+str(counter) newline = line.replace(oldstring, newstring) fileOUT.write(newline)

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 using

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 --

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

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 something

String manipulation

2007-04-04 Thread marco . minerva
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 and, in this case, replaces the spaces in the expression with the character _. For example, the text

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 and, in

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 can

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 phyton script that

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 --

Re: python challenge question (string manipulation)

2006-03-30 Thread Caleb Hattingh
Felipe I get the same results as you. You make a good point about not iterating when it's not needed. I played around with your test code and found some interesting things: 1. enumerate vs. range(len()) has very little overhead (something I have wondered about) In my code, making the change

python challenge question (string manipulation)

2006-03-29 Thread John Salerno
Ok, for those who have gotten as far as level 2 (don't laugh!), I have a question. I did the translation as such: import string alphabet = string.lowercase[:26] code = string.lowercase[2:26] + 'ab' clue = g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw

Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
John Salerno wrote: It works, but is there a better way to shift the letters of the alphabet for 'code'? I remember a method that did this for lists, I think, but I can't remember what it was or if it worked for strings. Ah ha! This is cleaner: alphabet = string.ascii_lowercase code =

Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
John In python, strings are immutable - you have to create a new string no matter what you do. Also, I suspect you meant to say: alphabet = string.ascii_lowercase code = alphabet[2:] + alphabet[:2] I had a similar need recently for a guitar chord generator program I've been working on. Here

Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
Caleb Hattingh wrote: Also, I suspect you meant to say: alphabet = string.ascii_lowercase code = alphabet[2:] + alphabet[:2] Ah yes, I see what you did there. :) I actually create a new list here, although since lists are mutable, I could probably just change items in-place. There is

Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
Em Qua, 2006-03-29 às 19:34 +, John Salerno escreveu: alphabet = string.ascii_lowercase code = string.ascii_lowercase[2:] + string.ascii_lowercase[:2] Yet it still seems kind of verbose. But since that's the official solution, I guess there's no other way to shift the characters in a

Re: python challenge question (string manipulation)

2006-03-29 Thread Terry Reedy
John Salerno [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] John Salerno wrote: It works, but is there a better way to shift the letters of the alphabet for 'code'? I remember a method that did this for lists, I think, but I can't remember what it was or if it worked for strings.

Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
Terry That is very succint. Rewriting my shift function given earlier: import string alpha = string.ascii_lowercase print alpha abcdefghijklmnopqrstuvwxyz def shift(lst, n): return [lst[(i+len(lst)-n)%len(lst)] for i,item in enumerate(lst)] print shift(alpha,2) ['y', 'z', 'a',

Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
Em Qua, 2006-03-29 às 22:20 -0800, Caleb Hattingh escreveu: That is very succint. Rewriting my shift function given earlier: import string alpha = string.ascii_lowercase print alpha abcdefghijklmnopqrstuvwxyz def shift(lst, n): return [lst[(i+len(lst)-n)%len(lst)] for i,item in

String Manipulation Help!

2006-01-28 Thread Dave
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: --- 6: */- 7: - 8: CODE

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 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 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 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 think

Re: Filepath string manipulation help

2005-11-04 Thread mjakowlew
Steve, the os commands don't run through zope, it denies access to them to be run at all through the webserver. So in turn, I had to use a work around to fix the IE problem. Also qwwee's suggestion to use: filepath.split('\\')[-1] works well too. Zope is very finicky about running specific

Re: Filepath string manipulation help

2005-11-04 Thread Steve Holden
mjakowlew wrote: Steve, the os commands don't run through zope, it denies access to them to be run at all through the webserver. So in turn, I had to use a work around to fix the IE problem. Also qwwee's suggestion to use: filepath.split('\\')[-1] works well too. Zope is very finicky

Re: Filepath string manipulation help

2005-11-04 Thread robert . dowell
I just assumed he had heard of me and knew better than to take my advice. :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Filepath string manipulation help

2005-11-03 Thread mjakowlew
Thanks guys. The os.path method works, but this is for a script for a website upload program on a zope webserver. For some reason even admin access won't let me run the script through the server. The main issue with my script is that Firefox has no problem with the program the way it is, but IE

Re: Filepath string manipulation help

2005-11-03 Thread qwweeeit
Hi mjakowlew, to get file basename in Linux I use simply: filepath.split('/')[-1] But in Windows, being the dir separator '\', you get into trouble if the dir or file name begins with one of the escape sequences: \a ASCII Bell(BEL) \x07 \b ASCII Backspace (BS) \x08 \f

Re: Filepath string manipulation help

2005-11-03 Thread mjakowlew
I got the IE Fix working, here's the code: path = r'c:\here\there\files\file.ext' i=len(path) j=0 size=len(path) while i: i=i-1 if path[i]== '\\': j=i+1 break filename = path[j:size] print FILENAME: %s %(filename) ___ Most

Re: Filepath string manipulation help

2005-11-03 Thread Steve Holden
mjakowlew wrote: I got the IE Fix working, here's the code: path = r'c:\here\there\files\file.ext' i=len(path) j=0 size=len(path) while i: i=i-1 if path[i]== '\\': j=i+1 break filename = path[j:size] print FILENAME: %s %(filename)

Filepath string manipulation help

2005-11-02 Thread mjakowlew
Hi, I'm trying to use some string manipulation from a file's path. filepath='c:\documents\web\zope\file.ext' I need to extract everthing after the last '\' and save it. I've looked around and have tried the sub, search, match commands, but I'm guessing '\' is set aside for switches. I need

Re: Filepath string manipulation help

2005-11-02 Thread robert . dowell
import os print os.path.basename(filepath) -- http://mail.python.org/mailman/listinfo/python-list

Re: Filepath string manipulation help

2005-11-02 Thread Fredrik Lundh
mjakowlewwrote: filepath='c:\documents\web\zope\file.ext' I need to extract everthing after the last '\' and save it. that string doesn't contain what you think it does: filepath='c:\documents\web\zope\file.ext' filepath 'c:\\documents\\web\\zope\x0cile.ext' print filepath

Re: help in simplification of code [string manipulation]

2005-09-14 Thread Christophe
John a écrit : Thanks for your replies... Solved my problem. Even so, I made a big mistake here. The Split function is of no use because there is already a list of flags. Better do it like that : libs = Split('glut GLU GL m') env.Append (LIBS = libs) BTW, Split is a scons function.

Re: help in simplification of code [string manipulation]

2005-09-14 Thread John
But ur previous solution worked on my machine... although a friend tried it on his machine and the libraries were not found even if they existed! (Even the -lm was not found) Can you explain a bit why the previous solution worked? Thanks for ur help, --j --

help in simplification of code [string manipulation]

2005-09-13 Thread John
How could I simplify the code to get libs out of LDFLAGS or vice versa automatically in the following python/scons code? if sys.platform[:5] == 'linux': env.Append (CPPFLAGS = '-D__LINUX') env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm') env.Append(CPPPATH=['include',

Re: help in simplification of code [string manipulation]

2005-09-13 Thread Kent Johnson
John wrote: How could I simplify the code to get libs out of LDFLAGS or vice versa automatically in the following python/scons code? if sys.platform[:5] == 'linux': env.Append (CPPFLAGS = '-D__LINUX') env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')

Re: help in simplification of code [string manipulation]

2005-09-13 Thread Christophe
John a écrit : How could I simplify the code to get libs out of LDFLAGS or vice versa automatically in the following python/scons code? if sys.platform[:5] == 'linux': env.Append (CPPFLAGS = '-D__LINUX') env.Append (LDFLAGS = '-lglut -lGLU -lGL -lm')

Re: help in simplification of code [string manipulation]

2005-09-13 Thread John
Thanks for your replies... Solved my problem. --j Christophe wrote: John a écrit : How could I simplify the code to get libs out of LDFLAGS or vice versa automatically in the following python/scons code? if sys.platform[:5] == 'linux': env.Append (CPPFLAGS = '-D__LINUX')

String Manipulation

2005-07-13 Thread Michael Jordan
i'll be straight with you and say that this is a homework assignment. ive tried to figure it out on my own but am now out of time. i need to go through a .txt file and get rid of all punctuation. also, every time i see the work Fruitloops=1 or Hamburgers=x where x is ANY number i need to get rid

String Manipulation

2005-07-13 Thread Michael Jordan
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. thanks guys. cheerio :). jen --

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

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 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-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 and types.

String manipulation

2005-04-13 Thread Nicholas Graham
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 print the character corresponding to the results of the operation. For example, the pseudo-code

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 print