回覆列表
  • 1 # ymihe1396

    #用enumerate函式,最好不要用index ,因為列表有相同的元素的時候,index就傻冒了for i,j in enumerate(("a","b","c")): print i,j 0 a1 b2 c

  • 2 # 使用者1430807591406

    1.

    a=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]

    b=[1,4,3,6,10]

    c = type(a)(map(lambda i:a[i], b)) #這裡沒有判斷 b的元素作為a的索引的時候 值太大 溢位的異常

    print c

    >>>

    ["b", "e", "d", "g", "k"]

    >>>

    ------------------------------

    2.

    >>> import numpy as np

    >>> b = np.array([2,3,4,5,6])

    >>> a = np.array([0,2,4])

    >>> b[a]

    array([2, 4, 6])

  • 中秋節和大豐收的關聯?
  • 地圖魚可以長多大?它吃什麼?