zer0uno
zer0uno

Reputation: 8030

Why isn't reversed() implemented for all collections?

Why is iter() implemented for all collections whereas reversed() isn't (e.g. dicts and sets don't implement it)? As the doc says reversed() returns a simple reverse iterator...

Upvotes: 0

Views: 54

Answers (1)

Mox
Mox

Reputation: 589

Dictionaries and sets are not ordered. This is easy to overlook when you consider that iteration over them is supported... but one cannot assume any particular order in which iter() will provide items from sets and dictionaries, so it would not make sense to define a way to reverse this order.

Upvotes: 4

Related Questions