0

月の順序を安定させるために、次のような辞書があります。

meses_ord = {'January':1, 'February': 2, 'March':3, ... }

また、次のような辞書のリストもあります。

fechas_ = [{'anyo': 2010, 'horas': Decimal('52.5'), 'month': 'March', 'importe': Decimal('4200.000')},
{'anyo': 2010, 'horas': Decimal('40.0'), 'month': 'February', 'importe':Decimal('3200.000')},
{'anyo': 2010, 'horas': Decimal('42.5'), 'month': 'April', 'importe': Decimal('3400.000')},
{'anyo': 2010, 'horas': Decimal('20.0'), 'month': 'January', 'importe': Decimal('1600.000')}]

月のキーに基づいて辞書のリストを並べ替えたい。

私は多くのことを試しましたが、どれもうまくいきませんでした:

fechas_ord = sorted(fechas_, key=operator.itemgetter(meses_ord[fechas_['mes']]))
4

2 に答える 2