Apply Operations Over Items In A List

Want to learn more? I recommend these Python books: Python for Data Analysis, Python Data Science Handbook, and Introduction to Machine Learning with Python.

Method 1: map()

```# Create a list of casualties from battles
battleDeaths = [482, 93, 392, 920, 813, 199, 374, 237, 244]
```
```# Create a function that updates all battle deaths by adding 100
def updated(x): return x + 100
```
```# Create a list that applies updated() to all elements of battleDeaths
list(map(updated, battleDeaths))
```
```[582, 193, 492, 1020, 913, 299, 474, 337, 344]
```

Method 2: for x in y

```# Create a list of deaths
casualties = [482, 93, 392, 920, 813, 199, 374, 237, 244]
```
```# Create a variable where we will put the updated casualty numbers
casualtiesUpdated = []
```
```# Create a function that for each item in casualties, adds 10
for x in casualties:
casualtiesUpdated.append(x + 100)
```
```# View casualties variables
casualtiesUpdated
```
```[582, 193, 492, 1020, 913, 299, 474, 337, 344]
```

Method 3: lambda functions

```# Map the lambda function x() over casualties
list(map((lambda x: x + 100), casualties))
```
```[582, 193, 492, 1020, 913, 299, 474, 337, 344]
```