get each pair from a string.
Vincent Davis
vincent at vincentdavis.net
Sun Oct 21 14:58:52 EDT 2012
@Emile,
I feel a little stupid, in my mind it was more difficult than in reality.
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.
Thanks again!
Vincent
On Mon, Oct 22, 2012 at 12:45 AM, Emile van Sebille <emile at fenx.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'
>>
>> I am not seeing a obvious way to do this without multiple for loops, but
>> maybe there is not :-)
>> In the end I am going to what to get triples, quads....... also.
>>
>>
> How far have you gotten? Show us the loops you're trying now and any
> errors you're getting.
>
> Emile
>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121021/800bf01e/attachment.html>
More information about the Python-list
mailing list