Reversing sorted dictionary in Python 3 -
i'm sorting dictionary key, i'd reverse order. i'm not getting joy few of examples have seen around web.
here sort
tempdict = collections.ordereddict(sorted(tempdict.items()))
now i'm trying:
reverse = collections.ordereddict(tempdict.items()[::-1]) reverse = collections.ordereddict(map(reversed, tempdict.items()))
but these not working. smartest , elegant way of sorting dictionary. yes know, dictionaries not used sorting, works us. thanks.
to sort in reverse order:
collections.ordereddict(sorted(tempdict.items(), reverse=true))
to reverse existing dict:
collections.ordereddict(reversed(list(tempdict.items())))
Comments
Post a Comment