Charles Sanders <[EMAIL PROTECTED]> writes:
> from itertools import izip, count
> d = dict(izip(l2,count()))
> pos = [ d[i] for i in l1 ]
> 
> or the more memory intensive
> 
> d = dict(zip(l2,range(len(l2))))
> pos = [ d[i] for i in l1 ]

If you're itertools-phobic you could alternatively write

  d = dict((x,i) for i,x in enumerate(l2))
  pos = [ d[i] for i in l1 ]

dict access and update is supposed to take approximately constant time,
btw.  They are implemented as hash tables.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to