Dictionary methods no longer return lists
In python 2, keys(), values() and items() returned lists. But in Python 3, they are dynamic views and to get these dynamic views to be lists, use the list() function to convert.
Ok, I get that but what the heck is a dynamic view? What is it used for?
When I google dynamic views, all 开发者_Python百科I get are web frame work type results. Nothing related to this.
Thanks
For Python view, look here: http://docs.python.org/library/collections.html
The Abstract Base Classes for collections include Views.
A dynamic view is an iterator over the underlying dictionary object. It's also a one-way, non-updatable relationship with that object.
The idea is that there can be more view-like things for other structures. Merely calling it an iterator can obscure the fact that it's iterating over an existing structure, and providing a "view" of that structure. Principally, the additional feature that's interesting is that a view is non-updatable.
In the relational database world, we use "view" to mean a table-like result set built from a query against one or more tables. It looks like a table (in the way a a dynamic view looks like an iterator). But it isn't a table, because it cannot (in general) be used to update the underlying table.
[DB experts will note that there are some kinds of SQL views which do tolerate updates, but they have to be carefully designed so permit this. In the general case, it isn't sensible to update through a view. And in some databases it isn't even possible.]
精彩评论