Mar-15-2017, 11:52 AM
Isnt str(x) == x if x is a string? I am not sure if there is any difference between
And yes, if ints should be sorted as a numbers and before/after strings, something more complicated would be needed. Actually in python 2 comparison between numbers and strings works quite well naturally:
sorted(d, key=str)and
sorted(d, key = lambda x : str(x) if type(x) == int else x)for keys being strings and ints.
And yes, if ints should be sorted as a numbers and before/after strings, something more complicated would be needed. Actually in python 2 comparison between numbers and strings works quite well naturally:
>>> sorted({4: 'four', 11: 'eleven', 1: 'one', 'ten': 10, 'seven': 7, 1.23: 'float'}) [1, 1.23, 4, 11, 'seven', 'ten']