Q:

Python dictionaries - Why do keys(), values() return lists, not sets?

From the discussion here I understand that dictionaries in general are not ordered, at least not in a reliable fashion. So why do the dictionary methods keys(), values(), items() return ordered lists instead of e.g. unordered sets? Is it just a matter of convenience or is there some underlying reasoning?

A:

They don't return lists or sets; they return views. Key views are set-like, and item views are set-like as long as the values are hashable, but value views cannot be set-like, as there can be duplicate values.
Before Python 3, they returned lists, but those methods predated the introduction of sets. Sets were introduced in Python 2.4, while keys/values/items have been around since at least 1.4, and probably before 1.0.

