Apr-26-2022, 10:45 PM
Python coders,
Is there a particular reason/change that causes this sort result between versions? How common is this kind of change in Python? Do most people just incrementally test their code in each new version?
Best,
David
2.7
Is there a particular reason/change that causes this sort result between versions? How common is this kind of change in Python? Do most people just incrementally test their code in each new version?
Best,
David
2.7
>>> d = {'IN':2, 'GE':2, 'AK':3, 'BEG':1} >>> n_l = sorted(d.items(), key=lambda x: (x[1], len(x[0]), x[0])) >>> new_d = {k:v for k,v in n_l} >>> new_d {'AK': 3, 'GE': 2, 'BEG': 1, 'IN': 2}3.10
>>> d = {'IN':2, 'GE':2, 'AK':3, 'BEG':1} >>> n_l = sorted(d.items(), key=lambda x: (x[1], len(x[0]), x[0])) >>> new_d = {k:v for k,v in n_l} >>> new_d {'BEG': 1, 'GE': 2, 'IN': 2, 'AK': 3}