List Flashcards

1
Q

How to add an item at the end of a list?

A

append(x)

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

How to extend a list by appending all the items from an iterable.

A

extend(iterable)

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

How to insert at a given position?

A

insert(i, x)

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

How to remove an item that is equivalent to x?

A

remove(x)

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

how to pop the last item?

A

pop()

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

how to clear a list?

A

clear()

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

How to get the index of a value?

A

index(x,[start,[end]]) start and end being a subsequence

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

How get the number of times a value appears in a list?

A

count(x)

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

How to sort the items in a list?

A

sort(key=None, reverse=Fqlse)

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

How to reverse a list?

A

reverse()

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

How to return a shallow copy of a list?

A

copy()

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

how to use a list as a queue?

A

from collections import deque
queue = deque([‘eric’,’john’)
queue.append(‘test’)
queue.popleft()

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

How to create a list with list comprehension? (lambda)

A

list(map(lambda x: x**2, range(10)))

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

How to create a list with list comprehension? (implicit lambda)

A

[x**2 for x in range(10)]

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

What does a list comprehension consist of?

A

expression followed by a for clause, then zero or more if clauses

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

How to delete an index in a list?

A

del a[0]