I can't find imap() in itertools in Python

后端 未结 2 1663
忘了有多久
忘了有多久 2021-02-11 16:56

I have a problem that I want to solve with itertools.imap(). However, after I imported itertools in IDLE shell and called itertools.imap(), the IDLE shell told me that itertools

2条回答
  •  攒了一身酷
    2021-02-11 17:03

    If you want something that works in both Python 3 and Python 2, you can do something like:

    try:
        from itertools import imap
    except ImportError:
        # Python 3...
        imap=map
    

提交回复
热议问题