Re: rot13 in a more Pythonic style?

2007-02-16 Thread Andy Dingley
On 14 Feb, 20:06, "Beej" <[EMAIL PROTECTED]> wrote: > http://linuxgazette.net/109/pramode.html Thanks, that's a _really_ interesting link (Oh, I need to learn Scheme!) My code now looks like this, which I'm starting to feel much happier about in a functional sense. c_rot = lambda c, chars :

Re: rot13 in a more Pythonic style?

2007-02-16 Thread Steven D'Aprano
On Fri, 16 Feb 2007 04:53:23 +, Dennis Lee Bieber wrote: > On 15 Feb 2007 11:10:53 -0800, "Andy Dingley" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> >> Fortunately I don't think it's _quite_ that bad. > > Possibly not, but that description of the problem wo

Re: rot13 in a more Pythonic style?

2007-02-15 Thread Andy Dingley
On 15 Feb, 17:55, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > Sounds more like a case for a parser/lexer wherein the emitted "code > tokens" are the "new style" identifiers... 8-(I'm trying not to think about that Fortunately I don't think it's _quite_ that bad. -- http://ma

Re: rot13 in a more Pythonic style?

2007-02-15 Thread [EMAIL PROTECTED]
On Feb 14, 11:46 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 14 Feb 2007 14:04:17 -0300, Andy Dingley <[EMAIL PROTECTED]> > escribió: > > > I still don't understand what a lambda is _for_ in Python. I know what > > they are, I know what the alternatives are, but I still haven't fou

Re: rot13 in a more Pythonic style?

2007-02-15 Thread Andy Dingley
On 14 Feb, 21:59, Paul Rubin wrote: > Why don't you describe the actual problem instead of the rot13 analogy. I don't know what the actual problem is! I need to perform a complex mapping between "old style" structured identifiers and "new style" structured identifers. A

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Martin P. Hellwig
[EMAIL PROTECTED] wrote: > Martin P. Hellwig >> for me (personal) being Pythonic means that I should >> separate the logic and variables, etc... > > Well, for me me Pythonic means using built-in functionalities as much > as possible (like using encode("rot13") or translate), and to write > less co

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Paul Rubin
"Andy Dingley" <[EMAIL PROTECTED]> writes: > c_rot13 = lambdaf c : (((c, uc_rot13(c)) [c in > 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']), lc_rot13(c) )[c in > 'abcdefghijklmnopqrstuvwxyz'] Oh, I see what you mean, you have separate upper and lower case maps and you're asking how to select one in an expression

Re: rot13 in a more Pythonic style?

2007-02-14 Thread bearophileHUGS
Martin P. Hellwig > for me (personal) being Pythonic means that I should > separate the logic and variables, etc... Well, for me me Pythonic means using built-in functionalities as much as possible (like using encode("rot13") or translate), and to write less code, (avoiding overgeneralizations fro

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Paul Rubin
"Andy Dingley" <[EMAIL PROTECTED]> writes: > I'm trying to write rot13, but to do it in a better and more Pythonic > style than I'm currrently using. What would you reckon to the > following pretty ugly thing? How would you improve it? In > particular, I don't like the way a three-way selection

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Rob Wolfe
"Andy Dingley" <[EMAIL PROTECTED]> writes: > I'm trying to write rot13, but to do it in a better and more Pythonic > style than I'm currrently using. What would you reckon to the > following pretty ugly thing? How would you improve it? In > particular, I don't like the way a three-way selectio

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Beej
On Feb 14, 9:04 am, "Andy Dingley" <[EMAIL PROTECTED]> wrote: > I still don't understand what a lambda is _for_ in Python. Python supports functional programming to a certain extent, and lambdas are part of this. http://linuxgazette.net/109/pramode.html > I know what > they are, I know what the

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Gabriel Genellina
En Wed, 14 Feb 2007 14:04:17 -0300, Andy Dingley <[EMAIL PROTECTED]> escribió: > I still don't understand what a lambda is _for_ in Python. I know what > they are, I know what the alternatives are, but I still haven't found > an instance where it permits something novel to be done that couldn't

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Andy Dingley
On 14 Feb, 16:23, Neil Cerutti <[EMAIL PROTECTED]> wrote: > str.translate is what I'd do. That's what I hope to do too, but it might not be possible (for the live, complex example). It looks as if I have to make a test, then process the contents of the code differently depending. There might well

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Martin P. Hellwig
Andy Dingley wrote: > I'm trying to write rot13, but to do it in a better and more Pythonic > style than I'm currrently using. What would you reckon to the > following pretty ugly thing? How would you improve it? In > particular, I don't like the way a three-way selection is done by > nesting t

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Neil Cerutti
On 2007-02-14, Andy Dingley <[EMAIL PROTECTED]> wrote: > I'm trying to write rot13, but to do it in a better and more > Pythonic style than I'm currrently using. What would you > reckon to the following pretty ugly thing? How would you > improve it? In particular, I don't like the way a three-w

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Rune Strand
You could try "some_string".encode('rot_13') -- http://mail.python.org/mailman/listinfo/python-list

rot13 in a more Pythonic style?

2007-02-14 Thread Andy Dingley
I'm trying to write rot13, but to do it in a better and more Pythonic style than I'm currrently using. What would you reckon to the following pretty ugly thing? How would you improve it? In particular, I don't like the way a three-way selection is done by nesting two binary selections. Also I d