Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'lines:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'toss': 0.09; 'igor': 0.16; 'length.': 0.16; 'over:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'field,': 0.30; "i'm": 0.30; 'extract': 0.31; 'info.': 0.31; 'request,': 0.31; 'file': 0.32; 'subject:?': 0.36; 'hi,': 0.36; 'list': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'length': 0.61; 'kind': 0.63; 'received:pacbell.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: emile Subject: Re: What's correct Python syntax? Date: Tue, 14 Jan 2014 14:13:20 -0800 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-69-226-129-65.dsl.pltn13.pacbell.net User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389737616 news.xs4all.nl 2926 [2001:888:2000:d::a6]:53049 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63952 On 01/14/2014 02:05 PM, Terry Reedy wrote: > On 1/14/2014 3:46 AM, Igor Korot wrote: >> Hi, ALL, >> I'm trying to process a file which has following lines: >> >> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > >> However, I don't need all the protocol info. All I'm interested in is >> the last field, which is length. > > To directly extract only the needed info: > > >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, > length 30" > >>> s[s.rindex(' ')+1:] > '30' Any particular reason to prefer that over: >>> s.split()[-1] '30' Is it a length of s and speed or rindex over build and toss the list kind of thing? Emile