im very new to python, Im trying to count how many x I have in a 2D array, but list.count(x) gives me 0, but i know its not zero.
Im showing all my code. This code should do: read name and age from file, take maximum and minimum age and print in other file ALL with the same maximum and minimum age.
with open("duomenys.txt") as d:
sar = [line.split() for line in d]
max = 0
min = 200
for index, item in enumerate(sar):
if int(sar[index][1]) > max:
max = int(sar[index][1])
pozmax = index
for index, item in enumerate(sar):
if int(sar[index][1]) < min:
min = int(sar[index][1])
pozmin = index
with open('vyr_jaun.txt', 'w') as d:
d.write (sar[pozmin][0]+' '+sar[pozmin][1]+'\n')
with open('vyr_jaun.txt', 'a') as d:
d.write (sar[pozmax][0]+' '+sar[pozmax][1])
this writes only one name and age in file
my duomneys.txt file:
Justas 23
Mantas 18
Rokas 33
Anzelmute 69
Ruta 11
Vilius 2
Monika 6
Petras 17
Stasys 26
Zose 13
Jurgis 2
Borisas 69
(note that your ages in the array are strings. This is not a problem.)