[Tutor] Unique Items in Lists

Alan Gauld alan.gauld at freenet.co.uk
Thu Jan 27 10:38:03 CET 2005


> for i in range(len(a)):
> for k in range(len(a)):

for k in range(i,len(a)):

is faster, and if you calculate len before starting the 
loops that will speed it up too. (You calculate len for 
each iteration of each loop!)

> if i != k:
> if a[i] == a[k]:
> print a[i]
> break

HTH

Alan G.


More information about the Tutor mailing list