I saw this question tonight. I had never heard of future_builtins
before this, and it got me wondering. future_builtins
only covers a few types, and
You can use viewkeys()
, viewitems()
and viewvalues()
in py2x.
>>> dict.viewkeys?
Type: method_descriptor
String Form:<method 'viewkeys' of 'dict' objects>
Namespace: Python builtin
Docstring: D.viewkeys() -> a set-like object providing a view on D's keys
What’s New In Python 3.0 :
- dict methods
dict.keys()
,dict.items()
anddict.values()
return “views” instead of lists. For example, this no longer works:k = d.keys()
;k.sort()
. Usek = sorted(d)
instead (this works in Python 2.5 too and is just as efficient).- Also, the
dict.iterkeys()
,dict.iteritems()
anddict.itervalues()
methods are no longer supported.
Bug : Backport dictviews to 2.7:
After talking to Guido, got rid of the future import magic in favour of just providing
viewkeys
,viewitems
andviewvalues
methods of dicts. This makes efficient 2.6-and-3.0dict
-using code possibly by making2to3
translate theview
-methods directly tokeys
/values
/items
in 3.0, and not wrapping everything inlist()
.
2to3
tool:
RefactoringTool: Refactored so.py
--- so.py (original)
+++ so.py (refactored)
@@ -1 +1 @@
-print dic.viewkeys()
+print(dic.keys())