There are actually different types of loops. And maybe this is about to be a lot to learn at once. But actually, all three of these things are useful together. So, buckle up!
### looping through lists
In Python, a list is an ordered collection of items that you can *iterate* through. There's a fancy coding word. Look, here's how it works:
```python
fruits = ["apple", "banana", "orange"]
for fruit in fruits:
print(fruit)
# Output:
# apple
# banana
# orange
```
That will print each fruit from the list individually.
If you want a particular item in a list, you can specify it like this. Just keep in mind, the *first* item in the list is number *zero*:
```python
fruits = ["apple", "banana", "orange"]
print( fruits[1] )
# Output: banana
```
You can also get the length of a list with the `len()` function:
```python
fruits = ["apple", "banana", "orange"]
print( len(fruits) )
# Output: 3
```
If you also create a `range()`, then you can iterate through the range. Which may be useful for things like:
```python
for number in range(6, 10):
print(number)
# Output:
# 6
# 7
# 8
# 9
fruits = ["apple", "banana", "orange"]
for index in range( len(fruits) ):
print("Index " + str(index) + ": " + fruits[index])
# Output:
# Index 0: apple
# Index 1: banana
# Index 2: orange
```
### dictionaries
You may not want your data in an ordered list, though. Maybe you have information that you'd rather give some names to, but you don't want to make a gazillion variables. In that case, you want a dictionary:
```python
info = { "name": "Ben Hoff", "age": 28, "email": "
[email protected]", "teacher": True }
print( info["name"] ) # Output: Ben Hoff
```
See all the data types I put in there? Each of the "keys" needs to be a simple data type like a string or a number, but the "values" could be anything, including complicated things, like lists:
```python
info = {
"name": "Ben Hoff",
"age": 28,
"email": "
[email protected]",
"teacher": True,
"pets": ["Howl", "Cooper", "Hank"]
}
print( info["name"] + " has " + str(len(info["pets"])) + " pets!")
for pet in info["pets"]:
print(pet)
# Output:
# Ben Hoff has 3 pets!
# Howl
# Cooper
# Hank
```
You could also, if it becomes relevant, create a list of dictionaries:
```python
questions = [
{
"question": "What's your favorite food?",
"answers": ["Hot Dog", "Hamburger", "Sushi", "Salad"]
},
{...}
]
```
I hope you see where this is going.
## instructions
Update your buzzfeed quiz to store all of your questions and potential answers in a single list of dictionaries. Then, iterate through that list and ask the questions.