# [Tutor] How to calculate high value from multiple lines for each column

Alan Gauld alan.gauld at btinternet.com
Tue Feb 23 20:06:55 EST 2016

```On 23/02/16 20:33, Fosiul Alam wrote:
>
> so there are 2 dm (dm-30 and dm-31) wich 3 sample value
>
> dm-30             1.47    36.48    2.82    0.66   270.84   148.56
> 240.96     0.06   44.99  18.27   6.36
> dm-31             1.47    36.49    2.82    0.66   270.85   148.58
> 240.94     0.06   45.03  18.28   6.37
> dm-30             0.00     0.00    0.00    0.00     0.00     0.00
> 0.00     0.00    0.00   2.00   1.00
> dm-31             0.00     0.00    0.00    0.00     0.00     0.00
> 0.00     0.00    0.00   3.00   1.50
> dm-30             0.00     0.00    0.00    0.00     0.00     0.00
> 0.00     0.00    0.00   0.40   0.50
> dm-31             0.00     0.00    0.00    0.00     0.00     0.00
> 0.00     0.00    0.00   0.70   0.60
>
> Basically I am interested with 10 and 11 ( last 2 column) with bellow
> 2 way
>
> a) ignore the firsrt value for each dm  ( so line number 1 and 2 will
> totally ignore)  : I am having trouble to do that

We can do that at the end, just before getting the max().

> b) get the max value for clumn 10 and 11 for each dm (dm-30 and dm-31)
> : I am having to do that

> def _get_io():
>
>         with open (DM,'r')as f:
>         return content
>
>
> s_value= dict()
> u_value=dict()
>

You don't need two variables here, just one will do, lets just call it
values.

> if __name__ == '__main__':
>
>         dm_data=_get_io()
>
>         for line in dm_data:
>

You missed the line that split the fields

fields = line.split()

>                 if fields[0] in s_value:
>                         s_value[fields[0]].append(fields[10])
>                 else:
>                         s_value[fields[0]]=[fields[10]]
>

We can tidy that up using the setdefault() method:

data = values.setdefault(fields[0],[ [],[] ])     # return
lists if avail else empty lists
data[0],append(float(fields[10])
data[1],append(float(fields[11])

See if that gets you closer.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

```