Re: comparing two lists and returning position

2007-06-25 Thread Charles Sanders
hiro wrote: 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) Glad to see you solved the problem with the trailing space. Just one minor point, I did say or

Re: comparing two lists and returning position

2007-06-25 Thread Paul Rubin
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 =

Re: comparing two lists and returning position

2007-06-22 Thread hiro
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 = [

Re: comparing two lists and returning position

2007-06-22 Thread Steven D'Aprano
On Fri, 22 Jun 2007 03:11:16 +, hiro wrote: Hi there, I have a 2 lists.. for simplicities sake lets say the are: l1 = [ 'abc' 'ghi' 'mno' ] l2 = [ 'abc' 'def' 'ghi' 'jkl 'mno' 'pqr'] what I need to do is compare l1 against l2 and return the position of where each object in l1 is in

Re: comparing two lists and returning position

2007-06-22 Thread hiro
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 =

Re: comparing two lists and returning position

2007-06-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], hiro wrote: 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

Re: comparing two lists and returning position

2007-06-22 Thread hiro
On Jun 22, 1:56 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], hiro wrote: 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

Re: comparing two lists and returning position

2007-06-22 Thread hiro
On Jun 22, 1:58 pm, hiro [EMAIL PROTECTED] wrote: On Jun 22, 1:56 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], hiro wrote: 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

Re: comparing two lists and returning position

2007-06-22 Thread hiro
On Jun 22, 2:00 pm, hiro [EMAIL PROTECTED] wrote: On Jun 22, 1:58 pm, hiro [EMAIL PROTECTED] wrote: On Jun 22, 1:56 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], hiro wrote: Hi once again, Charles.. I have tried your approach in my data set l2 and it

Re: comparing two lists and returning position

2007-06-21 Thread Neil Cerutti
On 2007-06-22, hiro [EMAIL PROTECTED] wrote: Hi there, I have a 2 lists.. for simplicities sake lets say the are: l1 = [ 'abc' 'ghi' 'mno' ] l2 = [ 'abc' 'def' 'ghi' 'jkl 'mno' 'pqr'] what I need to do is compare l1 against l2 and return the position of where each object in l1 is in l2

Re: comparing two lists and returning position

2007-06-21 Thread Paul Rubin
hiro [EMAIL PROTECTED] writes: what I need to do is compare l1 against l2 and return the position of where each object in l1 is in l2 ie: pos = 0, 2, 4 Is it September already? from itertools import izip pos = map(dict(izip(l2, count())).__getitem__, l1) Heh heh heh. --

Re: comparing two lists and returning position

2007-06-21 Thread Charles Sanders
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 --

comparing two lists and returning position

2007-06-21 Thread hiro
Hi there, I have a 2 lists.. for simplicities sake lets say the are: l1 = [ 'abc' 'ghi' 'mno' ] l2 = [ 'abc' 'def' 'ghi' 'jkl 'mno' 'pqr'] what I need to do is compare l1 against l2 and return the position of where each object in l1 is in l2 ie: pos = 0, 2, 4 Thanks in advance, -h --