Re: comparing two lists

2021-02-25 Thread Peter Otten
On 25/02/2021 01:42, Davor Levicki wrote: i have two lists list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] and when I loop through the list list_difference = [] for item in list1: if item not in list2: list_differen

Re: comparing two lists

2021-02-24 Thread MRAB
On 2021-02-25 00:42, Davor Levicki wrote: i have two lists list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] and when I loop through the list list_difference = [] for item in list1: if item not in list2: list_differen

Re: comparing two lists

2021-02-24 Thread Larry Martell
On Wed, Feb 24, 2021 at 4:45 PM Davor Levicki wrote: > > i have two lists > > list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] > list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] > > and when I loop through the list > > > list_difference = [] > for item in list1: > > if item no

comparing two lists

2021-02-24 Thread Davor Levicki
i have two lists list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] and when I loop through the list list_difference = [] for item in list1: if item not in list2: list_difference.append(item) and I managed to get the di

Re: comparing two lists

2010-03-05 Thread Terry Reedy
On 3/5/2010 3:05 AM, jimgardener wrote: hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst

Re: comparing two lists

2010-03-05 Thread Vlastimil Brom
2010/3/5 jimgardener : > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=

comparing two lists

2010-03-05 Thread jimgardener
hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst=['jon','arya','ned','bran'] newlst=['jaim

Re: comparing two lists, ndiff performance

2008-01-30 Thread Gabriel Genellina
On 29 ene, 22:47, Zbigniew Braniecki <[EMAIL PROTECTED]> wrote: > The new one is of course much better and cleaner (the old one is > bloated), but I'm wondering if there is a faster way to compare two > lists and find out what was added, what was removed, what was changed. > I can simply iterate t

Re: comparing two lists, ndiff performance

2008-01-30 Thread Zbigniew Braniecki
[EMAIL PROTECTED] wrote: > Zbigniew Braniecki: >> Is there a way to speed it up? Any easier way? Faster method? > > This problem is a bit messy. Maybe it's better to sidestep the > problem, and not use a list, and create an object that wraps the list, > so it always keeps an updated record of what

Re: comparing two lists, ndiff performance

2008-01-30 Thread bearophileHUGS
Zbigniew Braniecki: > Is there a way to speed it up? Any easier way? Faster method? This problem is a bit messy. Maybe it's better to sidestep the problem, and not use a list, and create an object that wraps the list, so it always keeps an updated record of what changes are done... but you have to

comparing two lists, ndiff performance

2008-01-29 Thread Zbigniew Braniecki
Hi all. I'm working on a tool for localizers. I have two Lists with Entities/Strings/Comments (each L10n file is built of those three elements). So I have sth like: l10nObject = [] l10nObject.append(Comment('foo')) l10nObject.append("string") l10nObject.append(Entity('name', 'value')) etc. I

Re: comparing two lists

2007-08-27 Thread Ladislav Andel
I have learnt a lot from your example and used it for my purpose. Thank you, it very helped me. Lada Peter Otten wrote: > Ladislav Andel wrote: > > >> need to be stopped before deleting any instance from items. >> So I need to call stopLoop method in the given item in items before it >> gets re

Re: comparing two lists

2007-08-24 Thread Peter Otten
Ladislav Andel wrote: > need to be stopped before deleting any instance from items. > So I need to call stopLoop method in the given item in items before it > gets removed. > If there is any addition to items it's quite easy to call > item.startLoop() method. Unless you want to rely on the __del_

Re: comparing two lists

2007-08-24 Thread Ladislav Andel
Peter Otten wrote: > Ladislav Andel wrote: > > >> Peter Otten wrote: >> >>> Ladislav Andel wrote: >>> >>> >>> what would be the most efficient way to do following? I have a list of dictionaries taken from DB e.g. dblist = [{'id:1, 'host':'google.com','ip_addre

Re: comparing two lists

2007-08-23 Thread Ladislav Andel
Peter Otten wrote: > Ladislav Andel wrote: > > >> Peter Otten wrote: >> >>> Ladislav Andel wrote: >>> >>> >>> what would be the most efficient way to do following? I have a list of dictionaries taken from DB e.g. dblist = [{'id:1, 'host':'google.com','ip_addre

Re: comparing two lists

2007-08-23 Thread Peter Otten
Ladislav Andel wrote: > Peter Otten wrote: >> Ladislav Andel wrote: >> >> >>> what would be the most efficient way to do following? >>> >>> I have a list of dictionaries taken from DB e.g. >>> dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, >>> {'id:3, 'host':'yahoo.com','ip_add

Re: comparing two lists

2007-08-23 Thread Ladislav Andel
Well, I know it's quite ugly what I did to the code, but any improvements are welcome. Actually, it doesn't work as it should yet. The items should stay the same as at the beginning. I say in one sentence what I want to achieve: Synchronized items with dblist. It should remove hosts from items whi

Re: comparing two lists

2007-08-23 Thread Ladislav Andel
Peter Otten wrote: > Ladislav Andel wrote: > > >> what would be the most efficient way to do following? >> >> I have a list of dictionaries taken from DB e.g. >> dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, >> {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'}, >> {'id:9, 'hos

Re: comparing two lists

2007-08-23 Thread Peter Otten
Ladislav Andel wrote: > what would be the most efficient way to do following? > > I have a list of dictionaries taken from DB e.g. > dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, > {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'}, > {'id:9, 'host':'msn.com','ip_address':'11.3.

Re: comparing two lists

2007-08-23 Thread Erik Jones
On Aug 23, 2007, at 11:27 AM, Ladislav Andel wrote: > Hi, > what would be the most efficient way to do following? > > I have a list of dictionaries taken from DB e.g. > dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, > {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'}, > {'id:9, '

Re: comparing two lists

2007-08-23 Thread Ladislav Andel
[EMAIL PROTECTED] wrote: > On Aug 23, 11:27 am, Ladislav Andel <[EMAIL PROTECTED]> wrote: > >> Hi, >> what would be the most efficient way to do following? >> >> I have a list of dictionaries taken from DB e.g. >> dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, >> {'id:3, 'host':

Re: comparing two lists

2007-08-23 Thread kyosohma
On Aug 23, 11:27 am, Ladislav Andel <[EMAIL PROTECTED]> wrote: > Hi, > what would be the most efficient way to do following? > > I have a list of dictionaries taken from DB e.g. > dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, > {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'}, >

comparing two lists

2007-08-23 Thread Ladislav Andel
Hi, what would be the most efficient way to do following? I have a list of dictionaries taken from DB e.g. dblist = [{'id:1, 'host':'google.com','ip_address':'1.2.3.4'}, {'id:3, 'host':'yahoo.com','ip_address':'5.6.7.8'}, {'id:9, 'host':'msn.com','ip_address':'11.3.2.3'}] and list of object in

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

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

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 d

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 mi

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)

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 s

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',

Re: comparing two lists and returning "position"

2007-06-21 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

Re: comparing two lists and returning "position"

2007-06-21 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

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

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. -- http://mail

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 i

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