Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31498

Re: Index in a list

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tolidtm@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'importing': 0.04; 'indexing': 0.07; 'stops': 0.07; 'cc:addr :python-list': 0.10; 'index': 0.13; '"user': 0.16; 'beginning.': 0.16; 'conditions;': 0.16; 'constructor.': 0.16; 'entries,': 0.16; 'matching.': 0.16; 'oct': 0.16; 'subject:Index': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'trying': 0.21; 'received:209.85.214.174': 0.21; "i'd": 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'specifically': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'looks': 0.26; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'chris': 0.28; 'loop,': 0.29; 'search.': 0.29; 'url:mailman': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'url:python': 0.32; 'file': 0.32; 'generally': 0.32; 'url:listinfo': 0.32; 'entry': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'or,': 0.34; 'thanks': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'list.': 0.35; 'but': 0.36; 'url:org': 0.36; 'skip:v 20': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'received:209.85.214': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'first': 0.61; "you'll": 0.62
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=j1G9jaRS3b0I8T1kkRFwqlU9DrP0wwzdxHD+BYlOTyY=; b=ZcUIQ9+KgKSQD6kGxoNON8F1btFv92wpgTspJHsE/gIQwKRSiFrO3Z+ShYOzo1H8iX 8TABAOFBk+zirTaOQB4Z6bJXGZCzbQhnX46P7fzMOwE0cDOO6cn/5RKp1ABU66y/6SXn QTZmaRteQZ4Y9vW8ObA/eIKRNDk7gycwyAjuZG52MFNo9g60GF5T8AfOiYyjVh6pWpzb JA5VsbCVkgYb2R3IWvv+PTVUXxYL97nrnIoSwlGnxOr+flJ0SX6E13cp7NaRMuSjzA/p HMRz0GxSSlTswRz72Ld0J0ur71CdT+GVX18sdBT6ywHkvutrH5fzsC+GaNZqYKAnHTLX vdVA==
MIME-Version 1.0
In-Reply-To <CAPTjJmq8V+nYzEsM7js4K5u9vCS4abvyd8dMtYFNC2tgPTAFsQ@mail.gmail.com>
References <CAKhY55P2-9GJtj_sZCPdJb2R00OZ3GXjZVixuDasn_Cisb_+yw@mail.gmail.com> <CAPTjJmq8V+nYzEsM7js4K5u9vCS4abvyd8dMtYFNC2tgPTAFsQ@mail.gmail.com>
Date Wed, 17 Oct 2012 14:38:52 +0200
Subject Re: Index in a list
From Anatoli Hristov <tolidtm@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc 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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2342.1350477535.27098.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350477535 news.xs4all.nl 6930 [2001:888:2000:d::a6]:47064
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31498

Show key headers only | View raw


Thanks a lot this solved my issue:)

Regards

Anatoli

On Wed, Oct 17, 2012 at 12:23 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Wed, Oct 17, 2012 at 9:10 PM, Anatoli Hristov <tolidtm@gmail.com> wrote:
>> Hello,
>>
>> I'm trying to index a text in a list as I'm importing a log file and
>> each line is a list.
>>
>> What I'm trying to do is find the right line which contains the text
>> User : and take the username right after the text "User :", but the
>> list.index("(User :") is indexing only if all the text matching. How
>> can I have the right position of the line which contains the word
>> ("(User :")
>
> What you want is a search. Try this:
>
> for idx,val in enumerate(list):
>     # if "(User:" in val: break
>     # if val.startswith("(User:"): break
>
>
> Pick one or t'other of those conditions; the first one looks for any
> string _containing_ "(User:", while the second will match specifically
> on the beginning.
>
> After this loop, list[idx] is the "User" line, and the entry after it
> is in list[idx+1] - but be aware that you'll get an exception if
> list[idx] is the last entry in the list.
>
> By the way, it's generally considered dodgy to use the name "list" for
> a list - it stops you from using the list constructor. I'd recommend
> calling it "lst" instead or, better, to name it according to what it
> contains (eg if it's a list of log entries, call it 'log_entries' or
> something).
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Index in a list Anatoli Hristov <tolidtm@gmail.com> - 2012-10-17 14:38 +0200

csiph-web