美文网首页
Python Notes: List

Python Notes: List

作者: 黑人不是牙膏 | 来源:发表于2017-05-11 19:24 被阅读0次

    This is to record some functions and attributes of Python I used before.

    the length of list:len(list)
    the type of list:type(…)

    How to get the index of 'bar'?

    ["foo", "bar", "baz"].index("bar”)

    How to find all indices of a repeated elements?

    (找出多个元素所有的index位置)
    [i for i, v in enumerate(resIndexList) if v==index]

    Iteration

    for i in range (0,len(list)): 
        print i ,list[i]
    
    # enumerate, get index and text info at the same time
    for index,text in enumerate(list)): 
       print index ,text
    

    Remove repeated elements

    set(list)
    list intersection, union, subset
    http://www.yihaomen.com/article/python/323.htm

    相关文章

      网友评论

          本文标题:Python Notes: List

          本文链接:https://www.haomeiwen.com/subject/vywgtxtx.html