List Methods Flashcards

1
Q

.append(elem)

A

(list method)

adds an element to the end of a list

returns None (modifies list in place)

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

.clear()

A

(list method)

removes all elements from the list

returns None (modifies list in place)

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

.copy()

A

(list method)

Returns a copy of the list

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

.count(elem)

A

(list method)

returns the number of elements with the specified value in the list

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

.extend([elem,elem])

A

(list method)

Add the elements of a list (or any iterable), to the end of the current list

returns None (modifies list in place)

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

.index(elem)

A

(list method)

Returns the index of the first element with the specified value

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

.insert(idx, elem)

A

(list method)

adds an element to the list at specified index

returns None (modifies list in place)

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

.pop(idx)

A

(list method)

removes element from specified position

default value is -1, meaning the last element in the list

Returns the removed element

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

.remove(elem)

A

(list method)

removes the first item with the specified value

returns None (modifies list in place)

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

.reverse()

A

(list method)

reverses the order of the list

returns None (modifies list in place)

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

.sort()

A

(list method)

sorts the list

returns None (modifies list in place)

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

len(list)

A

returns the number of elements in a list

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

List Slicing

list[start:end]

A

start idx is included in new list
end idx is not included in new list

returns the new list; leaves original list unmodified

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

sorted(list)

A

returns a new sorted list

.sort() is faster than sorted()

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