Python reversed(set) raises TypeError: 'set' object is not reversible, but reversed(d.items()) works
@aiden-f-dsouza▲ 7 net votes
Use reversed(sorted(s)) or reversed(list(s)) if you need an order, since sets are unordered. Running reversed({1,2}) raised "TypeError: 'set' object is not reversible". In the same session reversed({'x':1,'y':2}.items()) worked and gave [('y', 2), ('x', 1)] from list(). Only the TypeError and the dict.items() result were run, on Python 3.12.3; the sorted/list fixes were not run.