Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31916
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-10-22 23:47 -0700 |
| References | <CALyJZZURWQxgPTQcQo8kOdHkaOYbB6YE=U=vi6VrX9FoDH1gAQ@mail.gmail.com> <mailman.2594.1350845107.27098.python-list@python.org> <1a8e1d4b-dddc-48c6-aec8-8041bb559a30@u4g2000pbo.googlegroups.com> <177aa300-9863-44f3-94da-7bc11bff2eda@i7g2000pbf.googlegroups.com> |
| Message-ID | <7fdadf96-2ec2-43c7-a5e2-74228c06faca@googlegroups.com> (permalink) |
| Subject | Re: get each pair from a string. |
| From | wxjmfauth@gmail.com |
Le mardi 23 octobre 2012 06:59:49 UTC+2, rusi a écrit : > On Oct 22, 9:19 pm, rusi <rustompm...@gmail.com> wrote: > > > On 10/21/2012 11:33 AM, Vincent Davis wrote: > > > > > > > I am looking for a good way to get every pair from a string. For example, > > > > input: > > > > x = 'apple' > > > > output > > > > 'ap' > > > > 'pp' > > > > 'pl' > > > > 'le' > > > > > > Maybe zip before izip for a noob? > > > > > > >>> s="apple" > > > >>> [a+b for a,b in zip(s, s[1:])] > > > > > > ['ap', 'pp', 'pl', 'le'] > > > > Daniel wrote: > > > This is a little bit faster: > > > > > > s = "apple" > > > [s[i:i+2] for i in range(len(s)-1)] > > > > Nice! I always find pairs of structural decomposition of input vs > > recomposition of output interesting. > > In this case the use of slices: > > to decompose: s -> s[1:] > > vs doing s[i:i+2] Why bother with speeed? The latest Python version is systematically slower than the previous ones as soon as one uses non "ascii strings". Python users are discussing "code optimizations" without realizing the tool they are using, has killed itself its own performances. (Replace 'apple' with 'ap需') jmf
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: get each pair from a string. rusi <rustompmody@gmail.com> - 2012-10-22 09:19 -0700
Re: get each pair from a string. rusi <rustompmody@gmail.com> - 2012-10-22 21:59 -0700
Re: get each pair from a string. wxjmfauth@gmail.com - 2012-10-22 23:47 -0700
Re: get each pair from a string. Neil Cerutti <neilc@norwich.edu> - 2012-10-23 12:30 +0000
Re: get each pair from a string. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-23 13:44 +0100
Re: get each pair from a string. Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-23 10:41 -0600
Re: get each pair from a string. wxjmfauth@gmail.com - 2012-10-24 02:32 -0700
Re: get each pair from a string. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-24 13:14 +0100
Re: get each pair from a string. wxjmfauth@gmail.com - 2012-10-24 02:32 -0700
csiph-web