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


Groups > comp.lang.python > #91603

Re: What use for reversed()?

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: What use for reversed()?
Date 2015-06-01 01:30 +0100
References <514c05fc-dded-4278-ac86-3e8e3cd0e851@googlegroups.com> <CAN8CLgnm3ZVzzZHB4306nQdKh3Xwu8fBpL25P1Cy1+0EpvG=6g@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.255.1433121593.5151.python-list@python.org> (permalink)

Show all headers | View raw


On 01/06/2015 00:23, Tim Delaney wrote:
> On 1 June 2015 at 05:40, fl <rxjwg98@gmail.com
> <mailto:rxjwg98@gmail.com>> 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

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


Thread

What use for reversed()? fl <rxjwg98@gmail.com> - 2015-05-31 12:40 -0700
  Re: What use for reversed()? Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-31 19:58 +0000
    Re: What use for reversed()? Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-31 18:06 -0600
  Re: What use for reversed()? cheshire <supportNOSPAM@microsoft.com> - 2015-05-31 23:26 +0200
  Re: What use for reversed()? Tim Delaney <timothy.c.delaney@gmail.com> - 2015-06-01 09:23 +1000
    Re: What use for reversed()? fl <rxjwg98@gmail.com> - 2015-05-31 20:11 -0700
  Re: What use for reversed()? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-01 01:30 +0100
  Re: What use for reversed()? Tim Delaney <timothy.c.delaney@gmail.com> - 2015-06-01 13:59 +1000
  Re: What use for reversed()? fl <rxjwg98@gmail.com> - 2015-05-31 22:15 -0700
    Re: What use for reversed()? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-01 09:11 +0300

csiph-web