Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16519
| References | <roy-A03C06.22152730112011@news.panix.com> <jb8qmd$56l$1@dont-email.me> <4ed818bb$0$29988$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2011-12-02 13:07 +1100 |
| Subject | Re: Clever hack or code abomination? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3211.1322791680.27778.python-list@python.org> (permalink) |
On Fri, Dec 2, 2011 at 11:15 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Try this on for size.
>
>
> f = type(q)(c[c.index(chr(45))+1:])+type(q)(1)
> c = str.join('\n', list(map(chr, (45, 48))) + [c])[::2]
> c = (lambda a,b: a+b)(c[:c.index(chr(45))+1], type(c)(f))
I would consider integer representations of ASCII to be code smell.
It's not instantly obvious that 45 means '-', even if you happen to
know the ASCII table by heart (which most people won't). This is one
thing that I like about C's quote handling; double quotes for a
string, or single quotes for an integer with that character's value.
It's clearer than the Python (and other) requirement to have an actual
function call:
for (int i=0;i<10;++i) {
digit[i]='0'+i;
letter[i]='A'+i;
}
versus
for i in range(10):
digit[i]=chr(ord('0')+i)
letter[i]=chr(ord('A')+i)
Ignoring the fact that you'd probably use a list comp in Python, this
is imho a win for C.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Clever hack or code abomination? Roy Smith <roy@panix.com> - 2011-11-30 22:15 -0500
Re: Clever hack or code abomination? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-01 03:38 +0000
Re: Clever hack or code abomination? Matt Joiner <anacrolix@gmail.com> - 2011-12-01 14:49 +1100
Re: Clever hack or code abomination? Chris Angelico <rosuav@gmail.com> - 2011-12-01 19:21 +1100
Re: Clever hack or code abomination? John Ladasky <ladasky@my-deja.com> - 2011-12-06 11:19 -0800
Re: Clever hack or code abomination? Arnaud Delobelle <arnodel@gmail.com> - 2011-12-01 08:35 +0000
Re: Clever hack or code abomination? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-12-01 21:35 +0100
Re: Clever hack or code abomination? "Martin P. Hellwig" <martin.hellwig@gmail.com> - 2011-12-01 21:13 +0000
Re: Clever hack or code abomination? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-02 00:15 +0000
Re: Clever hack or code abomination? Chris Angelico <rosuav@gmail.com> - 2011-12-02 13:07 +1100
Re: Clever hack or code abomination? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-02 05:34 +0000
Re: Clever hack or code abomination? Chris Angelico <rosuav@gmail.com> - 2011-12-02 17:02 +1100
Re: Clever hack or code abomination? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-02 08:54 +0000
Re: Clever hack or code abomination? Chris Angelico <rosuav@gmail.com> - 2011-12-02 20:16 +1100
Re: Clever hack or code abomination? Terry Reedy <tjreedy@udel.edu> - 2011-12-01 21:49 -0500
Re: Clever hack or code abomination? Matt Joiner <anacrolix@gmail.com> - 2011-12-02 16:11 +1100
Re: Clever hack or code abomination? Chris Hulan <chris.hulan@gmail.com> - 2011-12-02 09:20 -0800
csiph-web