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
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
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
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
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,
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
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()
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
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
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
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
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
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
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)
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
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
--
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
[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
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
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
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
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
[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
--
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
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
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 =
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
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
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
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.
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',
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
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
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:
This is great, thanks!
--
http://mail.python.org/mailman/listinfo/python-list
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:
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
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
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
I just assumed he had heard of me and knew better than to take my
advice. :-)
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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)
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
import os
print os.path.basename(filepath)
--
http://mail.python.org/mailman/listinfo/python-list
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
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.
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
--
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',
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')
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')
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')
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
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
--
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
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.
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
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.
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
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
61 matches
Mail list logo