Python Lists Flashcards

1
Q

Methods for Lists

A

Append

Remove

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

List Method: Append

A

list.append(Object my_value) - Adds object to the end of the list

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

List Method: Remove

A

list.remove(Object my_value) - Removes the given object from the list
In a list with multiple instances of a value, only the first instance will be removed.

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

List Method: + (Concatenate)

A

list3 = list1 + list2 or list3 = list1 + [Object value1, Object value2]
append list2 to list1

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

List Method: [ ] (Square Brackets)

A

my_list[int index] - Retrieve the object that is referenced by the zero-indexed value
In Python, we can negatively index any element starting at -1 for the last element of the list, -2 for the second-to-last element and so on.

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

Multi-Dimensional List

A

Useful for representing grids

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

List Method: Count

A

my_list.count(Obj my_value) - Count the number of occurrences of an element in a list

return: int

time complexity: O(n)

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

List Method: Insert

A

my_list(int Index, Obj my_value) - Insert an element (my_value) into a specific index of a list.

returns: void

Time Complexity: O(n) unless element is added to end, and then O(1)

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

List Method: Pop

A

my_list.pop(int index = -1) - Remove an element from a specific index or from the end of a list. The index value is optional.

returns: popped element

Time Complexity: O(n) unless element is removed from the back, and then O(1)

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

List Method: Range (Python specific)

A

A built in Python function to create a sequence of integers

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

List Method: Len (Python specific)

A

A built in Python function to get the length of a list

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

List Method: Sort

A

my_list.sort() - Sort a list
To sort in reverse order -> my_list.sort(reverse=True)

return: void

time complexity: O(n log(n))

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