On Jun 22, 2:16 am, hiro <[EMAIL PROTECTED]> wrote: > On Jun 22, 1:46 am, Charles Sanders <[EMAIL PROTECTED]> > wrote: > > > Paul Rubin wrote: > > > > from itertools import izip > > > pos = map(dict(izip(l2, count())).__getitem__, l1) > > > or probably less efficiently ... > > > >>> l1 = [ 'abc', 'ghi', 'mno' ] > > >>> l2 = [ 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqr'] > > >>> pos = [ l2.index(i) for i in l1 ] > > >>> print pos > > [0, 2, 4] > > > Charles > > Hey Guys thanks for the feedback and the suggestions. > Charles I got your implementation to work so many thanks for this. > > this is what I had so far > > for spam in l1: > for eggs in l2: > if spam == eggs: > print "kaka", spam, eggs > > so its almost working just need the index, I'll > continue playing with the nested loop approach for a bit more. > > Thanks once again guys
Hi once again, Charles.. I have tried your approach in my data set l2 and it keeps crashing on me, bare in mind that I have a little over 10 million objects in my list (l2) and l1 contains around 4 thousand objects.. (i have enough ram in my computer so memory is not a problem) python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 error is : ValueError: list.index(x): x not in list when using Charles's pos = [ l2.index(i) for i in l1 ] print pos does anybody know of if I have to many data points ? the nested for loop approach seems to be working(still have get the index "position" returned though) Charles's approach works fine with less data. Cheers, -d -- http://mail.python.org/mailman/listinfo/python-list