• <small id='bpmpC'></small><noframes id='bpmpC'>

    <legend id='bpmpC'><style id='bpmpC'><dir id='bpmpC'><q id='bpmpC'></q></dir></style></legend>
      <bdo id='bpmpC'></bdo><ul id='bpmpC'></ul>

      1. <tfoot id='bpmpC'></tfoot>
      2. <i id='bpmpC'><tr id='bpmpC'><dt id='bpmpC'><q id='bpmpC'><span id='bpmpC'><b id='bpmpC'><form id='bpmpC'><ins id='bpmpC'></ins><ul id='bpmpC'></ul><sub id='bpmpC'></sub></form><legend id='bpmpC'></legend><bdo id='bpmpC'><pre id='bpmpC'><center id='bpmpC'></center></pre></bdo></b><th id='bpmpC'></th></span></q></dt></tr></i><div id='bpmpC'><tfoot id='bpmpC'></tfoot><dl id='bpmpC'><fieldset id='bpmpC'></fieldset></dl></div>
      3. 为什么 map 在 Python 3 中返回一个地图对象而不是一个列表?

        Why does map return a map object instead of a list in Python 3?(为什么 map 在 Python 3 中返回一个地图对象而不是一个列表?)
            <legend id='FqoFs'><style id='FqoFs'><dir id='FqoFs'><q id='FqoFs'></q></dir></style></legend>

            • <bdo id='FqoFs'></bdo><ul id='FqoFs'></ul>
                <tbody id='FqoFs'></tbody>

              <small id='FqoFs'></small><noframes id='FqoFs'>

              <i id='FqoFs'><tr id='FqoFs'><dt id='FqoFs'><q id='FqoFs'><span id='FqoFs'><b id='FqoFs'><form id='FqoFs'><ins id='FqoFs'></ins><ul id='FqoFs'></ul><sub id='FqoFs'></sub></form><legend id='FqoFs'></legend><bdo id='FqoFs'><pre id='FqoFs'><center id='FqoFs'></center></pre></bdo></b><th id='FqoFs'></th></span></q></dt></tr></i><div id='FqoFs'><tfoot id='FqoFs'></tfoot><dl id='FqoFs'><fieldset id='FqoFs'></fieldset></dl></div>

                  <tfoot id='FqoFs'></tfoot>
                  本文介绍了为什么 map 在 Python 3 中返回一个地图对象而不是一个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有兴趣了解 新Python 3.x的语言设计.

                  我很喜欢 Python 2.7 中的函数 map:

                  I do enjoy, in Python 2.7, the function map:

                  Python 2.7.12
                  In[2]: map(lambda x: x+1, [1,2,3])
                  Out[2]: [2, 3, 4]
                  

                  但是,在 Python 3.x 中,情况发生了变化:

                  However, in Python 3.x things have changed:

                  Python 3.5.1
                  In[2]: map(lambda x: x+1, [1,2,3])
                  Out[2]: <map at 0x4218390>
                  

                  我明白怎么做,但我找不到原因的参考.为什么语言设计者会做出这样的选择,在我看来,这会带来很大的痛苦.这是为了让开发人员坚持列表理解吗?

                  I understand the how, but I could not find a reference to the why. Why did the language designers make this choice, which, in my opinion, introduces a great deal of pain. Was this to arm-wrestle developers in sticking to list comprehensions?

                  IMO,列表自然可以认为是 Functors;我一直被认为是这样思考的:

                  IMO, list can be naturally thought as Functors; and I have been somehow been thought to think in this way:

                  fmap :: (a -> b) -> f a -> f b
                  

                  推荐答案

                  我认为当 根本dev/peps/pep-0289/" rel="noreferrer">生成器表达式 也存在,是它可以接受多个迭代器参数,这些参数都被循环并传递给函数:

                  I think the reason why map still exists at all when generator expressions also exist, is that it can take multiple iterator arguments that are all looped over and passed into the function:

                  >>> list(map(min, [1,2,3,4], [0,10,0,10]))
                  [0,2,0,4]
                  

                  这比使用 zip 稍微容易一些:

                  That's slightly easier than using zip:

                  >>> list(min(x, y) for x, y in zip([1,2,3,4], [0,10,0,10]))
                  

                  否则,它根本不会在生成器表达式上添加任何内容.

                  Otherwise, it simply doesn't add anything over generator expressions.

                  这篇关于为什么 map 在 Python 3 中返回一个地图对象而不是一个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                1. <legend id='Ua8ei'><style id='Ua8ei'><dir id='Ua8ei'><q id='Ua8ei'></q></dir></style></legend>
                      <tbody id='Ua8ei'></tbody>
                    <i id='Ua8ei'><tr id='Ua8ei'><dt id='Ua8ei'><q id='Ua8ei'><span id='Ua8ei'><b id='Ua8ei'><form id='Ua8ei'><ins id='Ua8ei'></ins><ul id='Ua8ei'></ul><sub id='Ua8ei'></sub></form><legend id='Ua8ei'></legend><bdo id='Ua8ei'><pre id='Ua8ei'><center id='Ua8ei'></center></pre></bdo></b><th id='Ua8ei'></th></span></q></dt></tr></i><div id='Ua8ei'><tfoot id='Ua8ei'></tfoot><dl id='Ua8ei'><fieldset id='Ua8ei'></fieldset></dl></div>
                      <bdo id='Ua8ei'></bdo><ul id='Ua8ei'></ul>

                          <small id='Ua8ei'></small><noframes id='Ua8ei'>

                            <tfoot id='Ua8ei'></tfoot>