I need to create a list of dictionary values, sorted based on whether or not the value is empty, my attempt gets the desired output but has to iterate twice over the dictionary, I was wondering if there was a way to do this only iterating once? My actual dictionary contains like 50,000 values and just iterating once would save some time when doing it repeatedly
d = {'id1':[],
'id2':[1],
'id3':[1]}
l = [v for v in d.values() if v]+[v for v in d.values() if not v]
print (l)
this is my desired output:
[[1], [1], []]