Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74147
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jsf80238@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.052 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'patterns': 0.04; '"""': 0.07; 'cc:addr:python-list': 0.11; 'def': 0.12; 'itertools': 0.16; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'task': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'consisting': 0.31; 'text': 0.33; 'url:python': 0.33; 'maybe': 0.34; 'could': 0.34; 'advice': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'url:library': 0.38; 'how': 0.40; 'break': 0.61; 'url:3': 0.61; 'times': 0.62; 'to:addr:gmail.com': 0.65; 'skip:r 30': 0.69; 'jul': 0.74; 'x):': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=FP/W0Go3RiggweB5y/f+mSegjh0uFTbpY/20LtIXuU4=; b=m0hno9Hh3uoNmYa04kEhsyyxBXpgb4uFi0Ci5Aoqq+hVQ0RmXcmLS8tewibxoy39TT /QfKZvt9JFfxZYnkhi5jg94XcHtR+Un+wuXj5mESRCw/G4dyfpa3v9RsmuK0FYIPlzxM ScFqyXj+XamT8+5npFgIZQvIw+F/fFWDE99DaYDip/6dvIXe/LD5y8wfs/pjrAJiP0iL K2lAwTOT6VtmwkKXsICdBveKJZ43dVEg6Xmwuovgu/Z6uRizon++vXZhG6dbNUb8bivF 6fOgg3tVjRjGrgPYg8zk3C9XMx9D8bCtp+UcIaIMZZXzD45EdlXFWyKDcfek3ZpzOw+K 7VWg== |
| MIME-Version | 1.0 |
| X-Received | by 10.224.134.201 with SMTP id k9mr55282429qat.59.1404790707892; Mon, 07 Jul 2014 20:38:27 -0700 (PDT) |
| In-Reply-To | <d580e76b-793e-435d-917b-613ae912a93f@googlegroups.com> |
| References | <d580e76b-793e-435d-917b-613ae912a93f@googlegroups.com> |
| Date | Mon, 7 Jul 2014 21:38:27 -0600 |
| Subject | Re: finditer |
| From | Jason Friedman <jsf80238@gmail.com> |
| To | gintare <g.statkute@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11615.1404790710.18130.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1404790710 news.xs4all.nl 2880 [2001:888:2000:d::a6]:60931 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74147 |
Show key headers only | View raw
On Mon, Jul 7, 2014 at 1:19 AM, gintare <g.statkute@gmail.com> wrote:
> If smbd has time, maybe you could advice how to accomplish this task in faster way.
>
> I have a text = """ word{vb}
> wordtransl {vb}
>
> sent1.
>
> sent1trans.
>
> sent2
>
> sent2trans... """
>
> I need to match once wordtransl, and than many times repeating patterns consisting of sent and senttrans.
You might try itertools.groupby
(https://docs.python.org/3/library/itertools.html#module-itertools).
text = """ word{vb}
wordtransl {vb}
sent1
sent1trans
sent2
sent2trans
"""
import itertools
import re
result_list = list()
lines = text.split("\n")
for line in lines[:]:
if line.startswith("sent"):
break
lines.pop(0)
def is_start(x):
pattern = re.compile(r"sent\d+$")
if re.search(pattern, x):
return True
for key, mygroup in itertools.groupby(lines, is_start):
result_list.append(list(mygroup))
print(result_list)
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
finditer gintare <g.statkute@gmail.com> - 2014-07-07 00:19 -0700 Re: finditer Jason Friedman <jsf80238@gmail.com> - 2014-07-07 21:38 -0600
csiph-web