List Flashcards

1
Q

How to create ordered list of numbers

A

my_list = list(range(10))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to get the reversed list

A

[::-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to add a new element at the certain position in a list

A

myList.insert(position, value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly