Python iterable map, range, etc
Why doesn't python have a __future__
library that replaces map
with im开发者_JAVA百科ap
, range
with xrange
, etc.? Is it possible to write one?
There is future_builtins
module since Python 2.6:
from future_builtins import filter, map, zip
A __future__
import is not necessary:
from itertools import imap as map
range = xrange
Edit: If you want to do several of those in a single line, you can do
from itertools import imap as map, ifilter as filter, izip as zip
range = xrange; input = raw_input
If you want to do this, why not add the following to your PYTHONSTARTUP file?
import itertools
filter = itertools.ifilter
map = itertools.imap
slice = itertools.islice
zip = itertools.izip
range = xrange
input = raw_input
精彩评论