Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'indexing': 0.07; 'oh,': 0.09; 'elements,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'function).': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'pythonistas': 0.16; 'received:192.168.1.4': 0.16; 'reversed': 0.16; 'subject:assistance': 0.16; 'sublist': 0.16; 'used:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'element': 0.18; '>>>': 0.20; '2015': 0.20; 'code,': 0.23; 'daniel': 0.23; 'elements': 0.23; 'sat,': 0.23; 'split': 0.23; 'words': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'order.': 0.27; '+0200,': 0.27; 'function': 0.28; 'necessary,': 0.29; 'probably': 0.31; 'another': 0.32; 'help,': 0.32; 'possibly': 0.32; 'maybe': 0.33; 'list': 0.34; 'but': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'method': 0.37; 'desired': 0.37; "won't": 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'subject:Need': 0.61; 'reverse': 0.66; 'here': 0.66; 'jul': 0.72; 'denis': 0.84; 'easier,': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JOrGyJ+b c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=JAI3OqB5mnwA:10 a=IkcTkHD0fZMA:10 a=sXHA8oGle9sPoosKW4EA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Subject: Re: Need assistance To: python-list@python.org References: <225d4ac6-3b88-4844-805b-b4b00cd62ef4@googlegroups.com> From: MRAB Date: Sun, 19 Jul 2015 17:35:03 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437323706 news.xs4all.nl 2840 [2001:888:2000:d::a6]:37579 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:94130 On 2015-07-19 01:59, Denis McMahon wrote: > On Sat, 18 Jul 2015 12:35:10 +0200, Sibylle Koczian wrote: > >> Am 18.07.2015 um 02:40 schrieb Denis McMahon: > >>> Having a list of words, get a copy of the list in reverse order. See >>> the reversed function (and maybe the list function). > >> That won't really help, because the desired order is, with the example >> the OP used: Sirna Daniel Craig. So here indexing is necessary, but >> indexing of the list elements, not of the characters in the string. > > Oh, then it's even easier, yes, it's mainly a case of list indexing. > > 1) Split the original string into a list of words (string.split() method) > 2) create a sublist (s1) of the last element > 3) create another sublist (s2) of the first to penultimate elements > 4) combine the two sublists > 5) use the string.join() method to combine the sublist elements into a > single string > > I think most pythonistas would probably combine steps 2 through 4 in a > single line of code, possibly even steps 2 through 5. > If you use rsplit, you can do it in one line.