On 27/07/2010 14:32, Vikram K wrote:
[['NM100', 3, 4, 5, 6, 7], ['NM100', 10, 11, 12, 13], ['NM200', 15,
16, 17]]
Possibly a little messy, but...
http://dpaste.com/222375/
All the best,
Alex
___
python-uk mailing list
python-uk@python.org
http
On 27/07/2010 14:32, Vikram K wrote:
how do i obtain from the above the following nested list:
Here's another solution, though possibly not a neat one:
> http://dpaste.com/222375/
All the best,
Alex
___
python-uk mailing list
python-uk@python.org
h
Just for clarification, you can do it also with a dictionary, but with a
defaultdict you can append directly items to a list if it's not set.
---
Check my blog!
http://wrongsideofmemphis.wordpress.com
On Tue, Jul 27, 2010 at 2:48 PM, Jaime Buelta wrote:
> You can use a defaultdict to order the i
You can use a defaultdict to order the items and then convert that back
again to a nested list:
>>> from collections import defaultdict
>>> d = defaultdict(list)
>>> for i in x:
... d[i[0]].extend(i[1:])
...
>>> d
defaultdict(, {'NM100': [3, 4, 5, 6, 7, 10, 11, 12, 13],
'NM200': [15, 16, 17]})
>>
Suppose i have this nested list:
>>> x
[['NM100', 3, 4, 5, 6, 7], ['NM100', 10, 11, 12, 13], ['NM200', 15, 16, 17]]
>>> for i in x:
... print i
...
['NM100', 3, 4, 5, 6, 7]
['NM100', 10, 11, 12, 13]
['NM200', 15, 16, 17]
>>>
how do i obtain from the above the following nested list:
>>> z
[['NM