user960567 user960567 - 1 year ago 228
Python Question

dict_items object has no attribute 'sort'Replace Min

First of all I am new to Python. I am using PTVS Next I installed reportlab. Then I run a sample demo at But at line,

all_colors = reportlab.lib.colors.getAllNamedColors().items()
all_colors.sort() # alpha order by name

I am getting error,
dict_items object has no attribute sort

Answer Source

Haven't tested but a theory: you are using python3!


dict methods dict.keys(), dict.items() and dict.values() return “views” instead of lists. For example, this no longer works: k = d.keys(); k.sort(). Use k = sorted(d) instead (this works in Python 2.5 too and is just as efficient).

as I understand it a "view" is an iterator, and an iterator does not have the sort function. Change it to


according to the documentation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download