Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Nathan Hilterbrand Newsgroups: comp.lang.python Subject: Re: Powerful perl paradigm I don't find in python Date: Fri, 15 Jan 2016 11:54:35 -0500 Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de qJgwfbK6BAkQ1Oq6KSLsiwamFec1ZaRFSXlzCjwNcdIQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.042 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'empty,': 0.09; 'str,': 0.09; 'subject:don': 0.09; 'def': 0.13; 'subject:python': 0.14; '"end"': 0.16; 'last;': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:{ 30': 0.16; 'wrote:': 0.16; 'string': 0.17; 'am,': 0.23; 'code,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'perl': 0.29; 'str': 0.29; 'tail': 0.29; 'probably': 0.31; 'maybe': 0.33; 'message-id:@gmail.com': 0.34; 'equal': 0.34; 'this?': 0.34; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'too': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'being': 0.37; '(2)': 0.37; 'received:209': 0.38; '(1)': 0.38; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'risk': 0.68; 'received:10.10': 0.76; 'smith': 0.76; 'nathan': 0.84; 'received:10.10.10': 0.84; 'too:': 0.84; 'subject:find': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=N3YowjP+EjtcgO+mwd2R0BlTIxKQshr9uGvsBI6bFVo=; b=QYOdcgGvsXbYFcoz7iXgg5KsV8PYlo/OK/95a538jqnnqLadyOZMm5dwc2t2uhzXjK d2RTEK6Rf87PmuIDa2RLGFkYzqRXhsB8nzgySIyURLBJ+BYpd7Q9wPtSELaXg/2DzAX3 /kFgh55QYbK31U+Ws4FiJli1/gXBgvLXERgFRPuvB2IZA9jciYvWEi1HdSUxrtkj1AY5 6L8wDlAG+iZvPxiVZBmymFSuFrCXk0L3N8vBo5PR2BEPNMqpoDpppHZFntCBfLOc3zTd SpHU0MJfbvSHQJY4ksSp9z1whmuLYDFMS6xu3G/V85Nn/egUcDa0qv1fh2/nLBr6qRrI QFiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=N3YowjP+EjtcgO+mwd2R0BlTIxKQshr9uGvsBI6bFVo=; b=cDuC4/4oMJ4mZw62HL8CNlhCBODQ1zx8TxyK57SYrXHhkejFkQIV6G5AU75sF1/D96 kGDiK2+n45Aa6jM4LMdwfpZ9rQmb4rheA3pk/Q/iLgMIHbUgNrh+2OtK3QeyiX7+CPWD yaS3VnqqNdHalsq34K2914u/ExZC0VVd8Gyq3azMc/0DqN7DmwXRvQ7TmnAnlImLD46A cukelOCHllEDgucB9b9c8dsjtv6trP7RPU113lE2Ge7buqD2sozFK/VUAiiOTDFTpqwD DLkEcaXRsq1o7pF9Ko7TKfYQAzGfW32pcI2QksA+Ysx7cXHQiAwOlXioHPB+u3KW6xFU E9aQ== X-Gm-Message-State: ALoCoQlfcXte5zdgFrQC0A8rx20clQM/qoyEmZOvi6yWe7wXxE5dWTYAw3M2rFRaHa/ooYpP6imWwq3fRzwznpxQpgfADCozeQ== X-Received: by 10.140.18.136 with SMTP id 8mr14524647qgf.64.1452876877195; Fri, 15 Jan 2016 08:54:37 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101766 On 01/15/2016 04:24 AM, Charles T. Smith wrote: > while ($str != $tail) { > $str ~= s/^(head-pattern)//; > use ($1); > } IDK... maybe the OP is looking for something like this? : import re def do_something(matchobj): print("I found {}".format(matchobj.group(0))) return "" tail = "END" str = "FeeFieFooFumEND" pattern = r"F.." while(str and str != tail): oldstr = str str = re.sub(pattern, do_something, str, 1) if str == oldstr: break Though I would probably change the perl code, too: while ($str and $str != $tail) { $str ~= s/^(head-pattern)//; if ($1) { do_something($1); } else { last; } } Otherwise there is too much risk of an infinite loop if the string is (1) empty, or (2) never ends up being equal to "tail" Nathan