Prison break project: provided code not working

I am on step 9 of 13, “Attempts per Year I” in the guided prison break project.
It has the following code to paste in:
(this is meant to get the earliest and latest years in the iterable named ‘data’)

min_year = min(data, key=lambda x: x[0])[0]
max_year = max(data, key=lambda x: x[0])[0]

(this is meant to give a list of all years from min_year to max_year)

years = []
for y in range(min_year, max_year + 1):

It says to paste this code into a new code cell. Then, create some other code.
The problem I’m having is that the provided code does not work. It gives me the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-4-999fac15da39> in <module>
----> 1 min_year = min(data, key=lambda x: x[0])[0]
      2 max_year = max(data, key=lambda x: x[0])[0]
      3 years = []
      4 for y in range(min_year, max_year + 1):
      5     years.append(y)

TypeError: '<' not supported between instances of 'str' and 'int'

I haven’t done much with python and I am unsure of how to solve this. Also, when I look at the data that I have printed, I do not see any ‘<’ character.
Here is a copy of my project thus far:

1 Like

Hi voyager1winterberry

Welcome to the community!!

Your notebook is not accessible at the link provided by you.
As per the Traceback.

This is the line that causes error. And the error is

That is, the code is using < to compare str and int datatypes in the min function. So, the year data you are passing to the min function is a String.
I guess you have missed the previous step, where you will invoke the fetch_year() method to pick the year in date and save it as integer in the data.
Please check and correct your code and let us know whether it works or not.



Hi @voyager1winterberry,

To upload your project, you can refer to this guide:

But it’s probably not necessary if @dash.debasmita’s answer has solved the problem you’re facing.


Thank you all for the assistance. I looked back at the fetch_year() part of my code and noticed that I had coded it incorrectly. I had coded this:

for row in data[0:3]:
    row[0] = fetch_year(row[0])

I changed it to this and the error is gone:

for row in data:
    row[0] = fetch_year(row[0])

The previous code was not looping through the entire data list, so there would have been a mixture of ints and strings which led to the error.