List Flashcards
1
Q
How to create ordered list of numbers
A
my_list = list(range(10))
2
Q
How to get the reversed list
A
[::-1]
3
Q
How to add a new element at the certain position in a list
A
myList.insert(position, value)
4
Q
Ways to remove item from a list
A
myList.remove(item)
removed_item = myList.pop() - removes the last item from the list and returns that value
removed_item = list.pop(index)
5
Q
List comprehension
A
myList = list[range(100)]
[2*item for item in myList]
filteredList = [item for item in myList if item % 10 < 3]