List Flashcards
How to add an item at the end of a list?
append(x)
How to extend a list by appending all the items from an iterable.
extend(iterable)
How to insert at a given position?
insert(i, x)
How to remove an item that is equivalent to x?
remove(x)
how to pop the last item?
pop()
how to clear a list?
clear()
How to get the index of a value?
index(x,[start,[end]]) start and end being a subsequence
How get the number of times a value appears in a list?
count(x)
How to sort the items in a list?
sort(key=None, reverse=Fqlse)
How to reverse a list?
reverse()
How to return a shallow copy of a list?
copy()
how to use a list as a queue?
from collections import deque
queue = deque([‘eric’,’john’)
queue.append(‘test’)
queue.popleft()
How to create a list with list comprehension? (lambda)
list(map(lambda x: x**2, range(10)))
How to create a list with list comprehension? (implicit lambda)
[x**2 for x in range(10)]
What does a list comprehension consist of?
expression followed by a for clause, then zero or more if clauses