[Baypiggies] Fwd: manipulating lists question

Michiel Overtoom motoom at xs4all.nl
Thu Dec 5 10:14:58 CET 2013


On Dec 5, 2013, at 10:09, Vikram K wrote:

> yes i am sure

In that case, I would use something like this:

x = [['cat', 'NM123', 12], ['cat', 'NM234', 12], ['dog', 'NM56', 65]]

import collections
d = collections.OrderedDict()

for key, label, quant in x:
    if key in d:
        d[key][0] += ", " + label
    else:
        d[key] = [label, quant]

y = list(d.iteritems())
print y



Greetings,


-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn Rand      





More information about the Baypiggies mailing list