Question: I'm trying to find the maximum rainfall from a data file. The precipitation column in the [4] element in a 1340 line long file. 
Here's an example of a line of data from the file:

```
Date,Day,High T,Low T,Precip,Snow,Snow Depth
1/1/10,1,41,19,0,0,5

```

Here's the loop I'm trying to find the max\_precip:

```
for line in fo:
    max_precip = max(line.split(",")[4])

```

Any help or guidance here would be greatly appreciated. Thanks guys!

Answer: 
You'll need to apply this to *all* lines, and you'll need to convert the precipitation value to integer first:

```
 max_precip = max(fo, key=lambda line: int(line.split(',')[4]))

```

This returns the *whole line* containing the maximum precipitation. I'm assuming you already removed the header line.

Note that you may want to look at the [`csv` module](https://docs.python.org/2/library/csv.html) to handle the comma-splitting for you.

To get *just* the precipitation maximum and ignore everything else, use a generator expression:

```
 max_precip = max(int(line.split(',')[4]) for line in fo)

```

Demo:

```
>>> fo = '''\
... 1/1/10,1,41,19,0,0,5
... 1/2/10,1,38,18,2,0,6
... 1/3/10,1,43,17,1,0,6
... '''.splitlines()
>>> max(fo, key=lambda line: int(line.split(',')[4]))
'1/2/10,1,38,18,2,0,6'
>>> max(int(line.split(',')[4]) for line in fo)
2

```
> 
> I'm trying to find the maximum rainfall from a data file.
> 
> 
> 

If that is what you want, you may want to pre-process your data, before passing to the built-in `max` function.

```
max_precip = max(int(line.split(',')[4]) for line in fo)

```