Computer (2nd Quarter) Flashcards
Making a list called “list” with the items: “Item1”, “Item2”, and “Item3”
list = [“Item1”, “Item2”, “Item3”];
List items are indexed, the first item has index:
0
Make the result “green”
colorlist = [ “red”, “blue”, “green”]
print(colorlist [ 2 ])
Adds an element at the end of the list
append( )
Adds an element at the specified position
insert( )
Removes the item with the specified value
remove( )
Removes all the elements from the list
clear( )
Add “black” to the end of the list “colorlist”
colorlist.append(“black”)
Add “white” to the beginning of the list “colorlist”
colorlist.insert(0, “white”)
Remove “blue” from the list “colorlist”
colorlist.remove(“blue”)
Clear the “colorlist”
colorlist.clear( )
Remove the element at the third position from the list “colorlist”
colorlist.pop(3)
Print “colorlist”
print(colorlist);
Add the elements of a list, to the end of the current list
extend( )
Extend “colorlist” by adding the list “numberlist”
colorlist.extend(numberlist)
Removes the element at the specified position
pop( )
Returns the index of the first element with the specified value
index( )
Print the index of “violet” in the list “colorlist”
print(colorlist.index(“violet”))
Returns the number of elements with the specified value
count( )
Print the number of times “violet” is in the list “colorlist”
print(colorlist.count(“violet”))
Sorts the list
sort( )
Sort the list “colorlist”
colorlist.sort( )
Reverses the list
reverse( )
Reverse the list “colorlist”
colorlist.reverse( )
Returns a copy of the list
copy( )
Make the list “colorlist2” a copy of the list “colorlist”
colorlist2 = colorlist.copy( )
While (one <= two), print (one) then add 1 to one
while (one<=two):
print(one);
one=one+1;