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
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
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
>
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
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
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
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
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
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 mai
"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:
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
>
>
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 the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list
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 a
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
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
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)
line=fileIN.readline()
[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
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
[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
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
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
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
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
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 c
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(
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',
"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 f
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
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.
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.
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 = st
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 fyl
"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
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 (
"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:
This is great, thanks!
--
http://mail.python.org/mailman/listinfo/python-list
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:
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
I just assumed he had heard of me and knew better than to take my
advice. :-)
--
http://mail.python.org/mailman/listinfo/python-list
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
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 com
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:
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)
___
Mo
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
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 so
"mjakowlew"wrote:
> 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
c:
import os
print os.path.basename(filepath)
--
http://mail.python.org/mailman/listinfo/python-list
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
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
--
http://mail.python.org/mailman/listi
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.
> Christ
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')
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')
> env.Append(CPP
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')
> env.Append(CPPPAT
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', 'incl
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
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
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
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
--
http://mail.python.org/mailman/listinfo/py
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
"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
"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
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 lo
62 matches
Mail list logo