Merging lists has made my brain hurt.

Dennis Lee Bieber wlfraed at ix.netcom.com
Wed Oct 2 20:44:39 EDT 2002


Huw Lynes fed this fish to the penguins on Wednesday 02 October 2002 
09:05 am:


> 
> This has me utterly stumped. Any help is appreciated.The only articles
> about merging strings that I've managed to find so far have been about
> merging strings so that you don't get repeats. Not quite what I'm
> looking for.
>
        There are no doubt better and faster methods... I haven't done enough 
with the new features of 2.x -- my biggest exposure was writing an SMTP 
send process for my Amiga back when 1.5 came out...


"""
    Brute force scan for common items in nested list
"""

nlist = [   ['aaa', 'bbb', 'ccc'],
            ['bbb', 'ccc', 'ddd'],
            ['ccc', 'ddd', 'eee', 'fff']
        ]


dct = {}
slcount = 0

for sl in nlist:
    slcount = slcount + 1
    for itm in sl:
        if dct.has_key(itm):
            dct[itm] = dct[itm] + 1
        else:
            dct[itm] = 1

olist = []
for itm in dct.keys():
    if dct[itm] == slcount:
        olist.append(itm)

print olist 


--
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list