From: Stephen Hansen on
On 7/1/10 12:45 AM, Terry Reedy wrote:
> On 7/1/2010 12:32 AM, Mladen Gogala wrote:
>> On Wed, 30 Jun 2010 21:04:28 -0700, Stephen Hansen wrote:
>
>>> However, you can easily get what you want by using the 'reversed'
>>> function (and similarly, the 'sorted' function), a la:
>>>
>>> >>> y = ''.join(reversed(list(x)))
>>>
>>> The 'reversed' and 'sorted' functions are generators that lazilly
>>> convert an iterable as needed.
>>
>> Ah, that is even better. Thanks.
>
> It is better if you do not mind making an unnecessary copy. If the list
> had 10 million elements, you might prefer your original.

The original that did not work? :)

--

... Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: Paul Rubin on
Terry Reedy <tjreedy(a)udel.edu> writes:
> sequential statements are a form of composition, even if
> strict functionalists do not like to see it that way.

They actually do like to see it that way:

http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html
From: Wolfram Hinderer on
On 1 Jul., 06:04, Stephen Hansen <me+list/pyt...(a)ixokai.io> wrote:
> The 'reversed' and 'sorted' functions are generators that lazilly
> convert an iterable as needed.

'sorted' returns a new list (and is not lazy).



From: Stephen Hansen on
On 7/1/10 5:29 AM, Wolfram Hinderer wrote:
> On 1 Jul., 06:04, Stephen Hansen<me+list/pyt...(a)ixokai.io> wrote:
>> The 'reversed' and 'sorted' functions are generators that lazilly
>> convert an iterable as needed.
>
> 'sorted' returns a new list (and is not lazy).

Oops, you're right. Got the two crossed into one in my head.

--

... Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: MRAB on
Zubin Mithra wrote:
>
> Er, I don't think you thought that one entirely through (/ tried it
> out):
>
>
> My Apologies.
>
> Here is a working one.
>
> >>> x="123"
> >>> t = list(x)
> >>> t.reverse()
> >>> print ''.join(t)
> 321
>
>
> But of course, the method which was suggested earlier is far more elegant.
>
> >>> print ''.join(reversed(list(x)))
>
If you want even more elegance, try slicing:

>>> x = "123"
>>> print x[ : : -1]
321