I have a data-structure which is something like this:
The population of three cities for different year are as follows.
Name 1990 2000 2010
A 10 20 30
B 20 30 10
C 30 10 20
I am using a defaultdict
to store the data.
from collections import defaultdict
cityPopulation=defaultdict(list)
cityPopulation['A']=[10,20,30]
cityPopulation['B']=[20,30,10]
cityPopulation['C']=[30,10,20]
I want to sort the defaultdict
based on a particular column of the list (the year).
Say, sorting for 1990, should give C,B,A
, while sorting for 2010 should give A,C,B
.
Also, is this the best way to store the data? As I am changing the population values, I want it to be mutable.