Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63901
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: What's correct Python syntax? |
| Date | 2014-01-14 08:47 -0500 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-78B570.08473514012014@news.panix.com> (permalink) |
| References | <mailman.5437.1389689219.18130.python-list@python.org> <cfd7f2f1-c8cb-4901-a6d7-630674ab20d4@googlegroups.com> <mailman.5439.1389691509.18130.python-list@python.org> <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> <mailman.5443.1389693753.18130.python-list@python.org> |
In article <mailman.5443.1389693753.18130.python-list@python.org>,
Igor Korot <ikorot01@gmail.com> wrote:
> I can do it this way:
>
> >>> testlist = test.split(',')
> >>> print testlist[2]
> my
>
> but it will needlessly creates a list on which I will access by the index.
Stop worrying about needlessly creating lists. Write the code in a way
that works and is easy to understand. If it turns out that it's not
running fast enough, then you can go back and optimize.
BTW, for those of you into code golf:
>>> line = '192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq
200, length 30'
>>> dict((k,int(v)) for k,v in (s.split() for s in line.split(', ')[1:]))
{'length': 30, 'id': 100, 'seq': 200}
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 00:46 -0800
Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 00:54 -0800
Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 01:25 -0800
Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 01:37 -0800
Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:02 -0800
Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 02:16 -0800
Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:35 -0800
Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 02:51 -0800
Re: What's correct Python syntax? Roy Smith <roy@panix.com> - 2014-01-14 08:47 -0500
Re: What's correct Python syntax? Peter Otten <__peter__@web.de> - 2014-01-14 12:33 +0100
Re: What's correct Python syntax? Ned Batchelder <ned@nedbatchelder.com> - 2014-01-14 07:19 -0500
Re: What's correct Python syntax? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-14 08:58 -0500
Re: What's correct Python syntax? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-14 09:37 +0000
Fwd: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:03 -0800
Re: Fwd: What's correct Python syntax? Larry Hudson <orgnut@yahoo.com> - 2014-01-14 22:00 -0800
Re: What's correct Python syntax? Alister <alister.ware@ntlworld.com> - 2014-01-14 10:59 +0000
Re: What's correct Python syntax? Roy Smith <roy@panix.com> - 2014-01-14 08:34 -0500
csiph-web