What use for reversed()?

fl rxjwg98 at gmail.com
Mon Jun 1 01:15:21 EDT 2015


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:
> 
> $ python
> Python 2.7.3 (default, Dec 18 2014, 19:10:20) 
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> "".join(list(reversed("fred")))
> 'derf'
> >>> "".join([x for x in reversed("fred")])
> 'derf'
> 
> So reversed can do it, but needs a little help
> 
> -- 
> Denis McMahon,

I follow your reply with these trials:

>>>>list_r=(reversed("fred"))
>>> list(list_r)
['d', 'e', 'r', 'f']
>>> list_r
<reversed object at 0x02B57F10>


I have searched about list, but I still don't know what list_r is.
It looks like an index in other language. 
What else can it be used besides list(list_r)?
I want to show list_r content. This is possibly an illegal question.

Thanks, 




More information about the Python-list mailing list