How to find largest number in file and see on which line it is
<p>The file looks like this:</p>

<pre><code>1, a b
2, c d
3, e f
</code></pre>

<p>my current code </p>

<pre><code>b = open('file.txt', 'r')

c = b.readlines()
regels = len(c)

print(regels)
</code></pre>

<p>I got the numbers of lines but still need biggest number + on which line it is. </p>

<ul>
<li>Read line </li>
<li>Split it on basis of comma</li>
<li>Append first element to temp list.</li>
</ul>

<p>Once complete reading of file is done,</p>

<ul>
<li>To get maximum number, just use <code>max</code> function on temp list.</li>
<li>Since file is read line by line sequentially and appending number from line to temp list, to get line number on which maximum number is present, just find the index of max number in temp list and increment it by one since list index starts with zero.</li>
</ul>

<p><strong>P.S :</strong> Check last three print statements</p>

<p><strong>Code:</strong></p>

<pre><code>num_list = []
with open('master.csv','r')as fh:
    for line in fh.readlines():
        num_list.append(int((line.split(','))[0]))

print num_list
print "Max number is -" ,max(num_list)
print "Line number is - ", (num_list.index(max(num_list)))+1
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
[1, 2, 3]
Max number is - 3
Line number is -  3

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

python