Python List Methods Flashcards

(26 cards)

1
Q

What does append() do?

A

Adds an element to the end of the list.

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

What does extend() do?

A

Appends elements from an iterable to the end of the list.

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

What does insert() do?

A

Inserts an element at a specified index in the list.

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

What does remove() do?

A

Removes the first occurrence of a specified value from the list.

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

What does pop() do?

A

Removes and returns the element at a specified index, or the last item.

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

What does clear() do?

A

Removes all elements from the list.

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

What does index() do?

A

Returns the index of the first occurrence of a specified value.

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

What does count() do?

A

Returns the number of occurrences of a specified value in the list.

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

What does sort() do?

A

Sorts the elements of the list in ascending order.

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

What does reverse() do?

A

Reverses the order of the elements in the list.

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

What does copy() do?

A

Creates a shallow copy of the list.

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

True or false: list() can convert other iterables to a list.

A

TRUE

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

Fill in the blank: slice returns a _______ of the list.

A

sublist

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

What does join() do?

A

Combines elements of a list into a single string, using a specified separator.

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

What does list comprehension do?

A

Creates a new list based on existing lists using a concise syntax.

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

What does max() do?

A

Returns the largest item in the list.

17
Q

What does min() do?

A

Returns the smallest item in the list.

18
Q

What does sum() do?

A

Returns the sum of all items in the list.

19
Q

What does any() do?

A

Returns True if any element of the list is true.

20
Q

What does all() do?

A

Returns True if all elements of the list are true.

21
Q

What does enumerate() do?

A

Returns an iterator that produces pairs of index and value from the list.

22
Q

What does zip() do?

A

Combines elements from multiple lists into tuples.

23
Q

What does filter() do?

A

Creates a list of elements for which a function returns true.

24
Q

What does map() do?

A

Applies a function to all items in the list and returns a new list.

25
What does **reduce()** do?
Applies a rolling computation to sequential pairs of values in the list.
26
What does **list slicing** allow you to do?
Access a subset of elements from the list using a range of indices.