You can use tricks like *rest, x, y = item_list
and then compare, but I think your method is great.
Chasing a "more pythonic" method for something you already have a great method for, is sometimes unnecessary. I do however encourage and like your attempt at getting better. Keep it up!
And if your asking about efficiency - Your method is probably the best there is.
Per your pondering in the comments:
Just so you'll understand how fast it is, which is in the order of nanosecods and same speed no matter the length, here is a benchmark:
> py -m timeit -s "a = list(range(10_000))" "a[-1]"
2000000 loops, best of 5: 73.3 nsec per loop
> py -m timeit -s "a = list(range(100_000))" "a[-1]"
5000000 loops, best of 5: 74.5 nsec per loop
> py -m timeit -s "a = list(range(1_000_000))" "a[-1]"
5000000 loops, best of 5: 69.6 nsec per loop
More than 10 billion lookups per second (on my old computer from 2009) is fast enough I think ;-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…