Lists - Chapter 10 Flashcards
Are lists mutable or immutable?
Mutable
The values in a list are called “ “ or sometimes “ “.
elements or items.
A list within another list is called?
Nested
A list with no elements is called?
An Empty List
If you need to write or update the elements in a list using indices. What built-in functions could you use?
range and len
for i in range(len(list)):
list[i] = list[i] * 2
Although a list can contain another list, the nested list still counts as a single….
Element
What will the outcome of this be?
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(c)
[1, 2, 3, 4, 5, 6]
What will the outcome of this be?
[1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
t = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’,]
What happens if we do the following?
t[:]
The slice will be a complete copy of the list.
What will the following output be?
t = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
t[1:3] = [‘x’, ‘y’]
print(t)
[‘a’, ‘x’, ‘y’, ‘d’, ‘e’, ‘f’]
This method takes a list as an argument and appends all of the elements.
**list.extend()
»> t1 = [1, 2, 3]
»> t2 = [4, 5, 6]
»> t1.extend(t2)
»> t1
[1, 2, 3, 4, 5, 6] **
” “ arranges the elements of a list from low to high.
**list.sort()
»> t = [‘c’, ‘d’, ‘a’, ‘b’, ‘e’]
»> t.sort()
»> t
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’] **
Most list methods are “ “; they modify the list and return “ “
void and return None
Give an example of an augmented assignment statement
variable += x
Which is equivalent to
** variable = variable + x**
A variable used to collect the sum of the elements is sometimes referred to as?
Accumulator
def capitalize(t):
res = []
for s in t:
res.append(s.capitalize())
return res
In this instance, res is the accumulator.