list methods Flashcards

(12 cards)

1
Q

Method to add a single element to the end of a list

A

.append(element)

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

Method to add elements from another iterable (like a list or tuple) to the end of the current list

A

.extend(iterable)

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

Method to insert an element at a specific position

A

.insert(index, element)

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

Method to remove and return the element at a specified position (defaults to the last item)

A

.pop([index])

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

Method to remove the first occurrence of a specified value

A

.remove(value)

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

Method to remove all elements from the list

A

.clear()

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

Method to return the index of the first occurrence of a value

A

.index(value, [start, end])

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

Method to count how many times a specified value appears in the list

A

.count(value)

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

Method to sort the list in place

A

.sort(key=None, reverse=False)

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

Method to reverse the order of the list in place

A

.reverse()

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

What function is used to create a new, sorted list from an existing list?

A

sorted(list) (This is a built-in function, not a method.)

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

How do you create a shallow copy of a list?

A

list.copy() or list[:]

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