<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                **map類** 咱們在匿名函數那一講使用了 map 類,現在來探討下 map 類是做什么的。 map 在Python3.5 中的源碼,只摘錄了下面咱們比較關注的部分 ~~~ class map(object): """ map(func, *iterables) --> map object 將傳入的方法作用于每個可迭代的元素,直到可迭代的元素迭代完才結束,從而產生新的迭代器。 Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted. """ def __init__(self, func, *iterables): # real signature unknown; restored from __doc__ pass ~~~ map 函數實際上調用的是 map 類,在初始化該累的時候,需要傳入一個方法,還有一個可迭代對象,map 將傳入的函數依次作用到序列的每個元素,并把結果作為新的 Iterator 返回。 舉例說明:map 處理字符串 ~~~ >>> def strLower(s):return s.lower() ... >>> map(strLower,'AirVip') <map object at 0x7f9c3db02b70> >>> >>> list(map(strLower,'AirVip')) ['a', 'i', 'r', 'v', 'i', 'p'] ~~~ 如圖所示 ![map](https://box.kancloud.cn/b20585895f8dc742e34656410793ef11_228x172.png) 從代碼中我么可以看出 map() 傳入的第一個參數是函數 strLower,調用之后,我們得到了一個 map 對象(Iterator),Iterator 是惰性序列,因需要通過 list() 函數讓它把整個序列都計算出來并返回一個 list,我們就看到最終的結果了。 **Demo** 將 數字字符串 轉換成 整形 列表 ~~~ >>> def char2num(s):return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] ... >>> list(map(char2num,'12345')) [1, 2, 3, 4, 5] ~~~ map 使用匿名函數 ~~~ >>> list(map(lambda x:x*x,[1,2,3,4,5])) [1, 4, 9, 16, 25] ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看