Reputation: 8030
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
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