I have the dict
d = {a: (None,), 'b': (None,), 'c 9:00': (32400,), 'd 10:23': (37380,)}
I need to get
{'c 9:00': (32400,), 'd 10:23': (37380,), a: (None,), 'b': (None,)}
How?
I have the dict
d = {a: (None,), 'b': (None,), 'c 9:00': (32400,), 'd 10:23': (37380,)}
I need to get
{'c 9:00': (32400,), 'd 10:23': (37380,), a: (None,), 'b': (None,)}
How?
You should first convert None values to some lager value (+ infinity) and then try to sort them, like
import math
for k,v in d.items():
if v[0] == None:
d[k[0]] = (math.inf,)
Now sorting by value
d_sorted = dict(sorted(d.items(), key = lambda x: x[1]))
output
{'c 9:00': (32400,), 'd 10:23': (37380,), 'a': (inf,), 'b': (inf,)}