Lists - Chapter 10 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Are lists mutable or immutable?

A

Mutable

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

The values in a list are called “ “ or sometimes “ “.

A

elements or items.

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

A list within another list is called?

A

Nested

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

A list with no elements is called?

A

An Empty List

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

If you need to write or update the elements in a list using indices. What built-in functions could you use?

A

range and len
for i in range(len(list)):
list[i] = list[i] * 2

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

Although a list can contain another list, the nested list still counts as a single….

A

Element

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

What will the outcome of this be?
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(c)

A

[1, 2, 3, 4, 5, 6]

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

What will the outcome of this be?
[1, 2, 3] * 3

A

[1, 2, 3, 1, 2, 3, 1, 2, 3]

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

t = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’,]
What happens if we do the following?
t[:]

A

The slice will be a complete copy of the list.

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

What will the following output be?
t = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
t[1:3] = [‘x’, ‘y’]
print(t)

A

[‘a’, ‘x’, ‘y’, ‘d’, ‘e’, ‘f’]

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

This method takes a list as an argument and appends all of the elements.

A

**list.extend()
»> t1 = [1, 2, 3]
»> t2 = [4, 5, 6]
»> t1.extend(t2)
»> t1
[1, 2, 3, 4, 5, 6] **

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

” “ arranges the elements of a list from low to high.

A

**list.sort()
»> t = [‘c’, ‘d’, ‘a’, ‘b’, ‘e’]
»> t.sort()
»> t
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’] **

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

Most list methods are “ “; they modify the list and return “ “

A

void and return None

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

Give an example of an augmented assignment statement

A

variable += x
Which is equivalent to
** variable = variable + x**

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

A variable used to collect the sum of the elements is sometimes referred to as?

A

Accumulator
def capitalize(t):
res = []
for s in t:
res.append(s.capitalize())
return res

In this instance, res is the accumulator.

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

An operation that changes a sequence of elements into a single value is sometimes called?

A

reduce

17
Q

What is the following operation called?
def only_upper(t):
res = []
for s in t:
if s.isupper():
res.append(s)
return res

A

A filter

18
Q

Most common list operations can be expressed as a combination of which 3 things?

A

map, filter, reduce

19
Q

” “ modifies the list and returns the element that was removed.

A

variable.pop()
»> t = [‘p’, ‘o’, ‘p’]
»> x = t.pop(1)
»> t
[‘p’]

20
Q

If you do not provide an index for pop, what happens?
»> t = [‘p’, ‘o’, ‘p’]
»> x = t.pop()
»> t

A

The last element is removed.
»> x
[‘p’]

21
Q

What is the return value for remove?

A

None

22
Q

A string is a sequence of characters and a list is a sequence of?

A

Values

23
Q

To convert from a string to a list, you can use?

A

list
»> b = ‘batman’
»> j = list(b)
»> j
[‘b’, ‘a’, ‘t’, ‘m’, ‘a’, ‘n’]

24
Q

The list function breaks a string into individual letters. If you want to break a string into words, what should you use?

A

variable.split()
»> s = ‘pining for the fjords’
»> t = s.split()
»> t
[‘pining’, ‘for’, ‘the’, ‘fjords’]

25
Q

An optional argument called a “ “ specifies which characters to use as word boundaries.

A

delimiter

26
Q

” “ is the inverse of split. It takes a list of strings and concatenates the elements.

A

join

27
Q

To check whether two variables refer to the same object, you can use the “ “ operator.

A

is

28
Q

If two objects are “ “, they are also equivalent, but if they are equivalent, they are not necessarily “ “.

A

identical

29
Q

If another list has the same elements, we say it has the
same value, but it is not the same “ “.

A

object

30
Q

The association of a variable with an object is called a “ “.

A

reference

31
Q

An object with more than one reference has more than one name, so we say that the object is “ “.

A

aliased

32
Q

If the aliased object is “ “, changes made with one alias affect the other.

A

mutable

33
Q

Before using list “ “ and operators, you should read the documentation carefully and then test them in interactive mode.

A

methods

34
Q

Define list:

A

A sequence of values

35
Q

Define element:

A

One of the values in a list (or other sequence), also called items

36
Q

A processing pattern that traverses a sequence and performs an operation on each element is called what?

A

map

37
Q

A processing pattern that traverses a list and selects the elements that satisfy some criterion.

A

filter

38
Q

Something a variable can refer to…

A

**object. An object has a type and a value. **

39
Q

A circumstance where two or more variables refer to the same object is called?

A

Aliasing