Chapter 4 Loops and Stuff Flashcards

1
Q

What is a list comprehension?

A

A line (singular) that does the same thing as a loop

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

Why would you use a list comprehension?

A

To make code more efficient

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

How do you notate a list comprehension, compared to a loop?

A

Function, for item in list

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

What is a slice?

A

Specific group of items in a list

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

What’s the notation for looping through a slice? What does it mean?

A

for item in items [:#]; python will print all items up to that number in the list

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

How do you round variables in f strings?

A

variable name: .#f

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

Why round variables in f-strings?

A

It prevents false accuracies

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

When round variables in f-strings?

A

When displaying a data set

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

What does *= mean? What does the rest of the notation look like if you were multiplying a value by 5

A

Perform the listed operation on a variable in a list; x *= 5

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