On 10/15/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 15 Oct 2007 14:47:30 +0200, Francesco Guerrieri wrote: > > >> def myreversed(sequence): > >> if isinstance(sequence, basestring): > >> return type(sequence)().join(reversed(sequence)) > >> else: > >> return type(sequence)(reversed(sequence)) > >> > >> (in fact, that's so simple I wonder why the built-in reversed() doesn't > >> do that). > > > > simple: > > In the face of ambiguity, refuse the temptation to guess. > > What ambiguity? What guess? The above is completely unambiguous: it > returns a sequence of the same type as the input. It doesn't support > xrange objects, but that's not really a great loss.
I could say that it depends on the xrange object.. but the truth is that I answered too quickly. Your suggestion was not ambiguous. Sorry :-) francesco -- http://mail.python.org/mailman/listinfo/python-list