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]
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