How to grouping by key and order by key in ascending using Python dictionary

Issue

This Content is from Stack Overflow. Question asked by coder_noob

I have several dictionary

{
('ABD12-GOU10', 'ASS 4W LINE 3'):[15,5],
('ABD13-GOU11', 'ASS 4W LINE 1'):[7,5],
('ABD13-GOU11', 'ASS 4W LINE 1'):[22,5],
('ABD14-GOU13', 'ASS 4W LINE 1'):[12,5],
('ABD14-GOU19', 'ASS 4W LINE 2'):[4,5],
('ABD14-GOU10', 'ASS 4W LINE 3'):[2,5],
('ABD14-GOU13', 'ASS 4W LINE 4'):[18,5],
('ABD14-GOU12', 'ASS 4W LINE 5'):[9,5],
('ABD14-GOU11', 'ASS 4W LINE 6'):[3,5],
}

How to grouping by key 2 ex: ASS 4W LINE 1 and order by key 1 ex: ABD12-GOu10. I want like this:

{
('ABD13-GOU11', 'ASS 4W LINE 1'):[7,5],
('ABD13-GOU11', 'ASS 4W LINE 1'):[22,5],
('ABD14-GOU13', 'ASS 4W LINE 1'):[12,5],
('ABD14-GOU19', 'ASS 4W LINE 2'):[4,5],
('ABD12-GOU10', 'ASS 4W LINE 3'):[15,5],
('ABD14-GOU10', 'ASS 4W LINE 3'):[2,5],
('ABD14-GOU13', 'ASS 4W LINE 4'):[18,5],
('ABD14-GOU12', 'ASS 4W LINE 5'):[9,5],
('ABD14-GOU11', 'ASS 4W LINE 6'):[3,5],
}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?