On 12 August 2010 09:44, Alan Gauld <alan.ga...@btinternet.com> wrote:
>> I'm wondering what's the fastet datatype in python to lookup the last
>> element in an ordered collection.
>
> When in doubt timeit()

Out of curiosity I used timeit and lists are faster if we iterate over
them one by one. Now this is my first go with the timeit module so
please do correct me :-). Code used is at
http://python.pastebin.org/475014.

def getLastItem(c):
    return [x[-1] for x in c]

The list/deque consists of 5000 items (lists or deques) with a length
21 random ints. Also for deque I used maxlen=26 which makes it a bit
faster.

List took 0.000693 seconds
693.01178383827209 / 100000 (default times run by timeit)

Deque took 0.009195 seconds
693.01178383827209 / 100000 (default times run by timeit)

How this applies to the OP situation I don't know..

Greets
Saner
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to