Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Scripting >> Python >> Examples >> List >> Demonstration of list methods

 

Initializes the list and reads Ncmd followed by Ncmd lines of text representing the commands to perform on the list

 

Ncmd = int(raw_input())
L = []
for i in range(1,Ncmd+1):
    S = raw_input()
    commands = S.split()
    if commands[0]=="insert":
        i=int(commands[1])
        e=int(commands[2])
        print "Insert into L integer",e,"at position",i
        L.insert(i,e)
        print L
    elif commands[0]=="append":
        e=int(commands[1])
        print "Append integer",e,"into L"
        L.append(e)
        print L
    elif commands[0]=="remove":
        e=int(commands[1])
        print "Remove integer",e,"from L"
        L.remove(e)
        print L
    elif commands[0]=="print":
        print L
    elif commands[0]=="sort":
        L.sort()
        print L
    elif commands[0]=="pop":
        L.pop()
        print L
    elif commands[0]=="reverse":
        L.reverse()
        print L
      

 


[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]