Helicopter Escape: 'int' is not scriptable TypeError

My Code:

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

What I expected to happen:

I expected the min year and max year variables to initialise and be able to be called in the next lines.

What actually happened:

I keep getting TypeError’s telling me the data ‘int’ is not scriptable. I had this error earlier with the index part and was able to fix it by using the ‘Restarting and run all’ function in Kernell tab. But it isn’t helping with this part.

Replace this line with the output/error


TypeError Traceback (most recent call last)
in
----> 1 min_year = min(data, key=lambda x: x[0])[0]
2 max_year = max(data, key=lambda x: x[0])[0]

in (x)
----> 1 min_year = min(data, key=lambda x: x[0])[0]
2 max_year = max(data, key=lambda x: x[0])[0]

TypeError: ‘int’ object is not subscriptable

Hi jackrasmussen1997
Welcome to the community!

Please follow these guidelines to ask questions.
You are getting a TypeError here. The reason could be, that you might have modified the value of data accidentally in your previous code cells. You code check the value using print(type(data)) or print(data[0])
You could also share your Notebook here for help.

Thanks,
Debasmita

I’m still very confused as i’m using direct code provided by dataquest:

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

yet it is still giving me type errors. My ‘data’ list has retained it’s list type for all of the code too.

I’ve seen other people uploading the same code and it works.

The same code is working for me too. Could you share the data in your previous code cell?

Guided Project_ Prison Break.tar (19 KB)

I’ve attached my Helicopter Escape attempt. Hopefully this grants you some insight.

Thank you again :slight_smile:

In cell #6, you have

index = 0

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

The result from fetch_year(row[0]) should be assigned to row[0], but you have assigned it to data[index].
Hence, the output for print(data[:3]) is
[1971, 1973, 1978]
rather than

[[1971, 'Santa Martha Acatitla', 'Mexico', 'Yes', 'Joel David Kaplan Carlos Antonio Contreras Castro'], [2020, 'Forest prison, Brussels', 'Belgium', 'No', 'Kristel A.'], [1978, 'United States Penitentiary, Marion', 'United States', 'No', 'Garrett Brock TrapnellMartin Joseph McNallyJames Kenneth Johnson', "43-year-old Barbara Ann Oswald hijacked a Saint Louis-based charter helicopter and forced the pilot to land in the yard at USP Marion. While landing the aircraft, the pilot, Allen Barklage, who was a Vietnam War veteran, struggled with Oswald and managed to wrestle the gun away from her. Barklage then shot and killed Oswald, thwarting the escape.[10] A few months later Oswald's daughter hijacked TWA Flight 541 in an effort to free Trapnell."]]

Change for loop to

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

and it will work.
Hope it’s clear now?