Lists Flashcards

1
Q

What are values inside a list called?

A

Elements

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

Rather than creating a variable for each new piece of data, we can collect related data inside a list using…

A

[ ] brackets

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

What’s the symbol for separating values in a list?

A

A comma ,

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

How many values can we store in a list?

A

As many as we’d like

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

Every element in a list has a numbered position called…

A

An Index

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

If there are four elements in a list, what is the number of the last index?

A

3 (because indices start from 0)

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

What do we call the position of an element in a list?

A

The element’s index

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

How do we update a value in a list?

A

We access the value by its index, then assign another value.

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

Which indices can we access in a list with two elements?

A

0 and 1

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

How do you add a value to the end of a list?

A

With append()

scores = [24, 23]
scores=.append(25)
print(scores)

[23, 24, 25]

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

Where does the added value appear when using .append()?

A

At the end of the list

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

How do we add a value to a specific index?

A

Use insert()

shopping = [“kiwis”, “peas”]
shopping.insert(0, lemon)
print(shopping)

[lemon, kiwis, peas]

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

What are the two parameters of a insert() function?

A
  1. The index where we want to insert the value
  2. The value to insert
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When using append() or insert() how many elements can we add to a list?

A

One at a time

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

How can we remove the last element in a list?

A

Use pop() as printed here

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

How can we remove an element at a specific index?

A

Use pop() with the index between the ()

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

What two instructions can add values to a list?

A

.append()
.insert()

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

How can we save the value removed by .pop()?

A

By storing it in a variable

gifts = [“earrings”, “chocolates”]
removed = gifts.pop()
print(removed)

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

What’s an easy way to loop through all elements of a list?

A

Using a for loop

19
Q

What is the configuration of a for loop?

A

The word “for”
A variable of our choice
The word “in”
Then the list name

20
Q

Where is the variable in this for loop?

for artist in artists

A

The variable before in holds the value of the list element the loop is currently on.

Artist

21
Q

How do we get the number of elements in a list?

A

By using the len() instruction.

users = [“Sarah”, “Mike”, “Ella”]

print(len(users))

22
Q

What instruction do we use to get the number of elements in a list?

A

len()

23
Q

How do you use the code max()?

A

To find the largest number in a list of data, code max() with the name of the list between the parentheses.

24
Q

How do you use the code min()?

A

To find the smallest number in a list of data, code min() with the name of the list between the parentheses

25
Q

How do you use the code sort()?

A

To sort a list, we code the list name, a dot . , and then sort()

26
Q

What does sort() do when applied on a list of numbers?

A

It sorts the numbers in ascending order.

27
Q

What happens when we sort a list containing both float and integer values?

A

The list elements are sorted according to their numeric value.

28
Q

How does sort() sort a list of strings?

A

In alphabetical order.

29
Q

How do we use the sum() function?

A

To calculate the total of a list, we use sum() with the list name between the parentheses, like sum(signups).

30
Q

What does sum() do when used on a list of numbers?

A

It sums up the numbers in the list.

31
Q

What happens when we use sum() on a list that contains negative numbers?

A

We’ll get the sum of the positive numbers, minus that of the negative.

32
Q

How can we reuse the result of sum()?

A

We save the result in a variable.

33
Q

What does the + operator do when used on two lists?

A

It joins the two lists elements into a new list.

34
Q

When coding list_1 + list_2 in which order will the elements appear in the new list?

A

The elements of list_1 will appear first then those of list_2

35
Q

What types of values can the lists we combine have?

A

Any type

36
Q

How can we reuse the list we get from joining two lists?

A

We save it in a variable

37
Q

How do we count how often a value appears in a list?

A

By using count()

38
Q

How is the count() action configured?

A

We start with the team name, a dot . , and then count(). Place the element in the parentheses that we are counting.

39
Q

What keyword can we use to learn if an element is present in a list?

A

We use the in keyword.

ingredients = [“flour”, butter”, “sugar”, “eggs”]

print(“sugar” in ingredients)

True

40
Q

What type is created when using the in keyword?

A

A Boolean (True or False)

41
Q

What does count() do when given a value?

A

It tells us how often that value appears in a list

42
Q

Where do we code the element that we want to count in a list?

A

Between the parentheses of .count()

43
Q

What can we use the in keyword for?

A

Checking if a list contains an element

44
Q
A