Biggest number in a text file
<p>I have a text file with numbers and names in the following format:</p>

<pre><code>129308123, Some Name
12390123, Some Other Name
</code></pre>

<p>I am trying to grab the biggest number in this textfile and also read on what line it is located. I tried multiple methods but none seem to be working for me. What am I doing wrong?</p>

<p>My code:</p>

<pre><code>file_in = open('kaartnummers.txt', 'r')
regels = len(file_in.readlines())

smallestInt = 0

intList = [int(x) for x in file_in.readlines()]


number = max(intList)
laatsteregel = ''

string_format = 'Deze file telt {0} regels\n' \
                'Het grootste kaartnummer is: {1} en dat staat op regel {2}'
result = string_format.format(regels, number, laatsteregel)
print(result)
</code></pre>

<p>To find the largest number in the file, split the line with <code>split</code></p>

<pre><code>file_in = open('kaartnummers.txt', 'r')

smallestInt = 0

intList = [int(x.split(",")[0]) for x in file_in.readlines()]
print(intList)
regels = len(intList)
number = max(intList)
laatsteregel = ''

string_format = 'Deze file telt {0} regels\n' \
                'Het grootste kaartnummer is: {1} en dat staat op regel {2}'
result = string_format.format(regels, number, laatsteregel)
print(result)
</code></pre>

<p><strong>kaartnummers.txt</strong></p>

<pre><code>11, Bob
22, James
33, Nick
23, Steve
25, John
21, Ken
</code></pre>

<p>Output</p>

<pre><code>python pyprog.py 
[11, 22, 33, 23, 25, 21]
Deze file telt 6 regels
Het grootste kaartnummer is: 33 en dat staat op regel 
</code></pre>

<p>To get the line number, you can use this code (remember it starts at 0)</p>

<pre><code>print("line number " + str(intList.index(max(intList))))
</code></pre>

python python-3.x