Reputation: 4276
I have a dictionary where the key is a tuple and the value is a list of lists. I'd like to modify my dictionary so that the remaining values are only the 2nd, 3rd, 5th elements of the current dictionary, instead of the 7 items that I have now (i.e. 06/20/2015, 00:00:00, 0005192500).
What would be the best way to go about that?
This is what my dictionary looks like.
{('A002', 'R051', '02-00-00', 'LEXINGTON AVE'): [['NQR456',
'BMT',
'06/20/2015',
'00:00:00',
'REGULAR',
'0005192500',
'0001756572 '],
['NQR456',
'BMT',
'06/20/2015',
'04:00:00',
'REGULAR',
'0005192550',
'0001756580
']],
('A002', 'R051', '02-00-01', 'LEXINGTON AVE'): [['NQR456',
'BMT',
'06/20/2015',
'00:00:00',
'REGULAR',
'0004801812',
'0001047813 '],
['NQR456',
'BMT',
'06/20/2015',
'04:00:00',
'REGULAR',
'0004801850',
'0001047821]]}
Upvotes: 0
Views: 31
Reputation: 6369
Another solution:
for key in d:
d[key] = [[l[2], l[3], l[5]] for l in d[key]]
Upvotes: 0
Reputation: 1238
One solution:
newDict = {k : map(lambda x: [x[2], x[3], x[5]], v) for k, v in dict.items() }
Upvotes: 1