Re: What use for reversed()?

2015-05-31 Thread Jussi Piitulainen
fl writes: > On Sunday, May 31, 2015 at 12:59:47 PM UTC-7, Denis McMahon wrote: >> On Sun, 31 May 2015 12:40:19 -0700, fl wrote: >> reversed returns an iterator, not a list, so it returns the reversed >> list of elements one at a time. You can use list() or create a list >> from reversed and then

Re: What use for reversed()?

2015-05-31 Thread fl
On Sunday, May 31, 2015 at 12:59:47 PM UTC-7, Denis McMahon wrote: > On Sun, 31 May 2015 12:40:19 -0700, fl wrote: > reversed returns an iterator, not a list, so it returns the reversed list > of elements one at a time. You can use list() or create a list from > reversed and then join the result:

Re: What use for reversed()?

2015-05-31 Thread fl
On Sunday, May 31, 2015 at 4:23:19 PM UTC-7, Tim Delaney wrote: > On 1 June 2015 at 05:40, fl wrote: > Hi, > > 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 (

Re: What use for reversed()?

2015-05-31 Thread Tim Delaney
On 1 June 2015 at 10:30, Mark Lawrence wrote: > On 01/06/2015 00:23, Tim Delaney wrote: > >> 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)

Re: What use for reversed()?

2015-05-31 Thread Ian Kelly
On Sun, May 31, 2015 at 1:58 PM, Denis McMahon wrote: > reversed returns an iterator, not a list, so it returns the reversed list > of elements one at a time. You can use list() or create a list from > reversed and then join the result: > > $ python > Python 2.7.3 (default, Dec 18 2014, 19:10:20)

Re: What use for reversed()?

2015-05-31 Thread Mark Lawrence
On 01/06/2015 00:23, Tim Delaney wrote: On 1 June 2015 at 05:40, fl mailto:rxjw...@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 ge

Re: What use for reversed()?

2015-05-31 Thread Tim Delaney
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 matc

Re: What use for reversed()?

2015-05-31 Thread cheshire
On Sun, 31 May 2015 12:40:19 -0700 (PDT), fl wrote: > 2. If reversed() is wrong the my purpose, what method can do it? i.e. '4321' > out. Try using slices: >>> b='1234' >>> b[::-1] '4321' https://docs.python.org/2/whatsnew/2.3.html#extended-slices -- https://mail.python.org/mailman/listinfo/py

Re: What use for reversed()?

2015-05-31 Thread Denis McMahon
On Sun, 31 May 2015 12:40:19 -0700, 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 > > > My questi

What use for reversed()?

2015-05-31 Thread fl
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 My questions: 1. What use for reversed(). I do not find an example on web. 2. If reversed() is wrong the my purpose, w