zoukankan      html  css  js  c++  java
  • Python List

    1. Basic

    list1 = ['math', 1, 2.3]
    

      

    2. Accessing

    list1 = ['math', 1, 2.3]
    list1[0]
    list1[1:2]
    

      

    3. delete

    list1 = ['math', 1, 2.3]
    del list1[0] #'math' will be deleted
    

      

    4. Built-in function

    cmp(list1, list2) #Compares elements of both lists.
    
    len(list) #Gives the total length of the list.
    
    max(list) #Returns item from the list with max value.
    
    min(list)
    
    list(seq) #Converts a tuple into list.
    
    list.append(obj) #Appends object obj to list
    
    list.count(obj) #Returns count of how many times obj occurs in list
    
    list.extend(seq) #Appends the contents of seq to list
    
    list.index(obj) #Returns the lowest index in list that obj appears
    
    list.insert(index, obj) #Inserts object obj into list at offset index
    
    list.pop(obj=list[-1]) #Removes and returns last object or obj from list
    
    list.remove(obj) #Removes object obj from list
    
    list.reverse() #Reverses objects of list in place
    
    list.sort([func]) #Sorts objects of list, use compare func if given
    

      

  • 相关阅读:
    CodeForcesGym 100524A Astronomy Problem
    ZOJ 2567 Trade
    HDU 3157 Crazy Circuits
    CodeForcesGym 100212E Long Dominoes
    UVALive 6507 Passwords
    [转]
    java socket
    Spark RDD Operations(2)
    Spark cache 和 persist
    vim 基础命令
  • 原文地址:https://www.cnblogs.com/KennyRom/p/6293712.html
Copyright © 2011-2022 走看看