Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'error:': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'syntax': 0.13; 'output': 0.15; 'iterator': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'run:': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'copied': 0.18; 'version.': 0.18; 'language': 0.19; '(on': 0.22; 'assuming': 0.22; 'fixing': 0.22; 'lawrence': 0.22; '2015': 0.23; 'specified': 0.23; 'header :In-Reply-To:1': 0.24; 'tim': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'error': 0.27; 'coded': 0.29; 'colon': 0.29; 'e.g.': 0.31; 'print': 0.31; 'language.': 0.32; 'subject:use': 0.33; 'to:addr:python-list': 0.35; 'something': 0.35; 'but': 0.36; 'statement': 0.36; 'hi,': 0.37; 'subject:: ': 0.37; 'received:org': 0.38; 'end': 0.39; 'means': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'mark': 0.40; 'back': 0.61; 'hope': 0.61; 'per': 0.61; 'above,': 0.63; 'complete': 0.63; 'our': 0.64; 'charset:windows-1252': 0.65; 'delaney': 0.84; 'pythonistas,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: What use for reversed()? Date: Mon, 01 Jun 2015 01:30:40 +0100 References: <514c05fc-dded-4278-ac86-3e8e3cd0e851@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-177-12.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.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: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433121593 news.xs4all.nl 2963 [2001:888:2000:d::a6]:46553 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91603 On 01/06/2015 00:23, Tim Delaney wrote: > On 1 June 2015 at 05:40, fl > wrote: > > Hi, > > I have a string b='1234'. I run: br=reversed(b) > > I hope that I can print out '4321' by: > > for br in b > > but it complains: > SyntaxError: invalid syntax > > > Any time you get a SyntaxError, it means that you have coded something > which does not match the specified syntax of the language version. > > Assuming you copied and pasted the above, I can see an error: > > for br in b > > The for statement must have a colon at the end of line e.g. a complete > for statement and block is: > > for br in b: > print br > > This will output the characters one per line (on Python 3.x), since that > is what the reversed() iterator will return. You will need to do > something else to get it back to a single string. Will it indeed? Perhaps fixing the syntax error will get something to print :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence