from random import randrange
data = [(randrange(8), randrange(8)) for x in range(8)]
And we have to test if the first item equals to one of a tail. I am curious, how we would do it in most simple way without copying tail items to the new list? Please take into account this piece of code gets executed many times in, say, update() method, and therefore it has to be quick as possible.
Using an additional list (unnesessary memory wasting, i guess):
head = data[0]
result = head in data[1:]
Okay, here's another way (too lengthy):
i = 1
while i < len(data):
result = head == data[i]
if result:
break
i+=1
What is the most Pythonic way to solve this? Thanks.