get each pair from a string.

rusi rustompmody at gmail.com
Mon Oct 22 12:19:35 EDT 2012


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']
>>>



More information about the Python-list mailing list