Lists Flashcards

1
Q

Build this list [0,0,0] two separate ways

A
  1. [0]*3
  2. list2 = [0,0,0]
    list2
  3. s = 1,0,0,0
    s[1:]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reassign ‘hello’ in this nested list to say ‘goodbye’ instead.
List3 = [1,2,[3,4,’hello’]]

A
  1. List3 [2][2] = ‘goodbye’
    List3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Sort the list below:
list4 = [5,3,4,6,1]

A
  1. list4.sort()
    list4
  2. sorted(list4)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the append method?

A

The append method is used to permanently add an item to the end of a list:
IN) List1 = [1,2,3]
IN) list1.append(‘added’)
IN) list1
OUT) [1,2,3, ‘added’]

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

list1 = [1,2,3, ‘this is a string’]
grab 3

A

List1.pop(2)
3

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

What is does .pop() do?

A

.pop() removes the last index by default but you can stiil specify which index to pop off.

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

sort this list in alphabetical order
new_list =[ ‘a’, ‘j’, ‘e’, ‘x’, ‘r’, ‘c’]

A

new_list.sort()

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

Sort this list in reverse order:
new_list=[ ‘a’, ‘j’, ‘e’, ‘x’, ‘r’, ‘c’]

A

new_list.reverse

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

What does it mean by nesting?

A

Nesting means that you can have data structures within data structures e.g. a list inside a list

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

Make a matrix with three lists

A

list_1=[1,2,3]
list_2=[4,5,6]
list_3=[7,8,9]

matrix = [list_1,list_2,list_3]

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

[[1,2,3], [4,5,6], [7,8,9]]

a. Grab the first item in the matrix object
b. Grab the first item of the first item in the matrix object

A

a. matrix[0]
[1,2,3]
b. matrix[0][0]
1

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

What is unique about a set?

A

They don’t allow for duplicate items

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

Use a set to find the unique values in the list below:
list5 = [1,2,2,33,4,4,11,22,3,3,2]

A

set(list5)
1,2,3,4,11,22,33

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

Show two of tuples built-in methods

A

.index to enter a value and return index
.count to count the number of times a value appears

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

In Python, what are lists

A

lists are a sequence that are constructed in brackets [] and commas seperating every element in the list

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