How to sort this type of dictionary in python2 [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
How do I sort a dictionary by value?
41 answers
How can I sort a dictionary by key?
25 answers
deli = {'deli1': 'bbb', 'deli': 'aaa', 'deli3': 'ccc'}
How to get the dictionary sorted through key
Finally, the printing results of value are as follows.
aaa, bbb, ccc
python python-2.7
marked as duplicate by juanpa.arrivillaga
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
How do I sort a dictionary by value?
41 answers
How can I sort a dictionary by key?
25 answers
deli = {'deli1': 'bbb', 'deli': 'aaa', 'deli3': 'ccc'}
How to get the dictionary sorted through key
Finally, the printing results of value are as follows.
aaa, bbb, ccc
python python-2.7
marked as duplicate by juanpa.arrivillaga
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How do I sort a dictionary by value?
41 answers
How can I sort a dictionary by key?
25 answers
deli = {'deli1': 'bbb', 'deli': 'aaa', 'deli3': 'ccc'}
How to get the dictionary sorted through key
Finally, the printing results of value are as follows.
aaa, bbb, ccc
python python-2.7
This question already has an answer here:
How do I sort a dictionary by value?
41 answers
How can I sort a dictionary by key?
25 answers
deli = {'deli1': 'bbb', 'deli': 'aaa', 'deli3': 'ccc'}
How to get the dictionary sorted through key
Finally, the printing results of value are as follows.
aaa, bbb, ccc
This question already has an answer here:
How do I sort a dictionary by value?
41 answers
How can I sort a dictionary by key?
25 answers
python python-2.7
python python-2.7
asked Nov 12 at 9:55
Scheinin
73
73
marked as duplicate by juanpa.arrivillaga
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by juanpa.arrivillaga
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 10:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
To print the values corresponding with sorted keys, just iterate over the sorted keys and lookup the value:
for key in sorted(deli):
print deli[key]
would output:
aaa
bbb
ccc
add a comment |
up vote
0
down vote
In Python2x, the order of the keys is not ensured. So you've to use OrderedDict if you want to maintain the order of keys in the dictionary (or a tuple of tuples).
import collections
sorted_deli = collections.OrderedDict()
for key in sorted(deli):
sorted_deli[key] = deli[key]
print(sorted_deli.values())
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
To print the values corresponding with sorted keys, just iterate over the sorted keys and lookup the value:
for key in sorted(deli):
print deli[key]
would output:
aaa
bbb
ccc
add a comment |
up vote
0
down vote
accepted
To print the values corresponding with sorted keys, just iterate over the sorted keys and lookup the value:
for key in sorted(deli):
print deli[key]
would output:
aaa
bbb
ccc
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
To print the values corresponding with sorted keys, just iterate over the sorted keys and lookup the value:
for key in sorted(deli):
print deli[key]
would output:
aaa
bbb
ccc
To print the values corresponding with sorted keys, just iterate over the sorted keys and lookup the value:
for key in sorted(deli):
print deli[key]
would output:
aaa
bbb
ccc
edited Nov 12 at 10:03
answered Nov 12 at 9:57
mhawke
58.2k75280
58.2k75280
add a comment |
add a comment |
up vote
0
down vote
In Python2x, the order of the keys is not ensured. So you've to use OrderedDict if you want to maintain the order of keys in the dictionary (or a tuple of tuples).
import collections
sorted_deli = collections.OrderedDict()
for key in sorted(deli):
sorted_deli[key] = deli[key]
print(sorted_deli.values())
add a comment |
up vote
0
down vote
In Python2x, the order of the keys is not ensured. So you've to use OrderedDict if you want to maintain the order of keys in the dictionary (or a tuple of tuples).
import collections
sorted_deli = collections.OrderedDict()
for key in sorted(deli):
sorted_deli[key] = deli[key]
print(sorted_deli.values())
add a comment |
up vote
0
down vote
up vote
0
down vote
In Python2x, the order of the keys is not ensured. So you've to use OrderedDict if you want to maintain the order of keys in the dictionary (or a tuple of tuples).
import collections
sorted_deli = collections.OrderedDict()
for key in sorted(deli):
sorted_deli[key] = deli[key]
print(sorted_deli.values())
In Python2x, the order of the keys is not ensured. So you've to use OrderedDict if you want to maintain the order of keys in the dictionary (or a tuple of tuples).
import collections
sorted_deli = collections.OrderedDict()
for key in sorted(deli):
sorted_deli[key] = deli[key]
print(sorted_deli.values())
answered Nov 12 at 9:58
hspandher
8,9741025
8,9741025
add a comment |
add a comment |