Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: get each pair from a string.

Reply
Thread Tools

Re: get each pair from a string.

 
 
Ian Kelly
Guest
Posts: n/a
 
      10-21-2012
On Sun, Oct 21, 2012 at 12:58 PM, Vincent Davis
<(E-Mail Removed)> wrote:
> x = 'apple'
> for f in range(len(x)-1):
> print(x[f:f+2])
>
> @Ian,
> Thanks for that I was just looking in to that. I wonder which is faster I
> have a large set of strings to process. I'll try some timings if I get a
> chance later today.


The solution you came up with is probably faster, but less general --
it will only work on sliceable sequences like strings, not arbitrary
iterables.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: get each pair from a string. Emile van Sebille Python 9 10-24-2012 12:14 PM
Re: get each pair from a string. Mark Lawrence Python 0 10-21-2012 07:05 PM
Re: get each pair from a string. Ian Kelly Python 0 10-21-2012 06:51 PM



Advertisments