Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.144 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.72; '*S*': 0.00; '21,': 0.07; 'oct': 0.16; 'later': 0.16; 'wrote:': 0.17; 'header:In-Reply-To:1': 0.25; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'faster,': 0.29; 'strings,': 0.29; 'probably': 0.29; 'that.': 0.30; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'faster': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; "i'll": 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'chance': 0.61; 'today.': 0.69; 'subject:get': 0.81; 'timings': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=sh4SC5VDiwvxfAWEtQxWiIC/hSbdJqkYB0A3+ZkVIXw=; b=oOo6zwPYXFB93THYdSVtY+K8fsrA99wQUWAEVq0p0t3yjAfNNpwMgOv0dFDpz1Th7l lcHkiL9IbzyWArXXfVEqap9HK54J+z4dRsdZihW0j/7hNb+Ffan2L0Wa55yha5vzif5k Fhxj8GoVw9A55l6ITnyqQy6MRoyfzqRBepvAej6cGQK4cYlwodVmABXevcgbBtug6a4X 6DNV258R1DrE123I2TwIAixED5gXt/RFzLjtvA98Kr5KM4b1JnNcBxCKniqdlFwWhoR3 T9AE3VIauG8ZdOIaz7GnhX6Rc/qFy0ryr17NO5Oa4p7B8m6V3MMzr7GHdxhgMOoA2Yh2 2yiw== MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Sun, 21 Oct 2012 13:06:11 -0600 Subject: Re: get each pair from a string. To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350846404 news.xs4all.nl 6887 [2001:888:2000:d::a6]:35414 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31857 On Sun, Oct 21, 2012 at 12:58 PM, Vincent Davis 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.