Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

loop through dictionary in key order python

# Loop through dictionary in key order
di = {'b': 2, 'c': 3, 'a': 1}
for k, v in sorted(di.items()):
    print(k, v)
# a 1
# b 2
# c 3
 
PREVIOUS NEXT
Tagged: #loop #dictionary #key #order #python
ADD COMMENT
Topic
Name
1+8 =