<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello rusi</div><div><br></div><div><div>This is a little bit faster:</div><div><br></div><div><div>s = "apple"</div><div>[s[i:i+2] for i in range(len(s)-1)]</div><div><br></div><div><br></div></div><div>>>> timeit("""s = "apple"</div><div>... [a+b for a,b in zip(s, s[1:])]""",number=10000)</div><div>0.061038970947265625</div><div><br></div><div>>>> timeit("""s = "apple"</div><div>... [s[i:i+2] for i in range(len(s)-1)]""",number=10000)</div><div>0.0467379093170166</div><div><br></div><div>Regards</div></div><div><br><blockquote type="cite"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>From: </b></span><span style="font-family:'Helvetica'; font-size:medium;">rusi <<a href="mailto:rustompmody@gmail.com">rustompmody@gmail.com</a>></span><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>Date: </b></span><span style="font-family:'Helvetica'; font-size:medium;">22 October 2012 17:19:35 IST<br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>To: </b></span><span style="font-family:'Helvetica'; font-size:medium;"><a href="mailto:python-list@python.org">python-list@python.org</a><br></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;"><span style="font-family:'Helvetica'; font-size:medium; color:rgba(0, 0, 0, 0.5);"><b>Subject: </b></span><span style="font-family:'Helvetica'; font-size:medium;"><b>Re: get each pair from a string.</b><br></span></div><br><br>On 10/21/2012 11:33 AM, Vincent Davis wrote:<br><br><blockquote type="cite">I am looking for a good way to get every pair from a string. For example,<br></blockquote><blockquote type="cite">input:<br></blockquote><blockquote type="cite">x = 'apple'<br></blockquote><blockquote type="cite">output<br></blockquote><blockquote type="cite">'ap'<br></blockquote><blockquote type="cite">'pp'<br></blockquote><blockquote type="cite">'pl'<br></blockquote><blockquote type="cite">'le'<br></blockquote><br>Maybe zip before izip for a noob?<br><br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">s="apple"<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">[a+b for a,b in zip(s, s[1:])]<br></blockquote></blockquote></blockquote>['ap', 'pp', 'pl', 'le']<br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><br><br><br><font class="Apple-style-span" color="rgba(0, 0, 0, 0.49804)"><b><br></b></font></blockquote></div><br></body></html>