Suppose I have the following dictionary:
{"A":["u","w"],"B":["t"],"C":["x","y","z"]}
How can I sort the dictionary by number of strings in the list in of each value so that it returns:
[("C",["x","y","z"]), ("A",["u","w"]), ("B":["t"])]
Because the value of "C" has three items in the list, "A" has two, "B" has one. I was thinking something along the lines of:
sorted(d.items(),key=operator.methodcaller(len(),tuple[1]),reverse=True)
Or
sorted(d.items(),key=(string, stringList):(len(stringList),string),reverse=True)
But both do not seem to work. Still quite new to sorting, so thanks for the help!