You tried this:
for i in range(0, len(allyears)):
allyears[i] = int(allyears[i])
and got the error
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
The next thing you should have tried is:
for i in range(0, len(allyears)):
print(allyears[i])
And you would have seen that you are looping through these values:
['1916']
['1919']
['1922']
etc.
Those cannot be converted to int using int()
, because those are lists. You should get the only element of those lists using the [0]
index like this:
>>> for i in range(0, len(allyears)):
... print(allyears[i][0])
1916
1919
1922...
And now you know how to correct your original code:
for i in range(0, len(allyears)):
allyears[i] = int(allyears[i][0])
The more Pythonic solution to your problem would use list comprehension:
allyears = [int(i[0]) for i in allyears]