On 08Jan2019 15:28, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:
>>> a = [1, 1, 1, 1, 1]
>>> a[1:] == a[:-1]
True
>>> a == a[::-1]
True
>>> a = [1, 2, 3, 4, 3, 2, 1]
>>> a[1:] == a[:-1]
False
>>> a == a[::-1]
True
Looks like Peter's pretty clever after all. :-)
Except that his solution always scans then entire list. Twice.
For large dissimilar lists this gets needlessly expensive in a linear
fashion with the length of the list.
It is succinct, but wasteful.
Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list