Guided Project: Prison Break, Screen 10 TypeError: 'int' object is not subscriptable

Hi Team & community

I’m in the process of completing the first project around prison breaks.

Through a lot of trial and error, I’ve managed to solve most errors myself, but am now stuck on Screen 10 - Attempts per year II.

for row in data: # Instruction 1 - for each row in data
for ya in attempts_per_year: # Instruction 2 - nothing to do here
y = ya[0]# Instruction 3 - assign the year value in ya to y
if row[0] == y:
ya[1] += 1

Instruction 4 - print the results

print (attempts_per_year)TypeError: ‘int’ object is not subscriptable
for row in data: # Instruction 1 - for each row in data
for ya in attempts_per_year: # Instruction 2 - nothing to do here
y = ya[0]# Instruction 3 - assign the year value in ya to y
if row[0] == y:
ya[1] += 1

Instruction 4 - print the results

print (attempts_per_year)

Output
TypeError: ‘int’ object is not subscriptable

My Q:
I’ve googled and found that when an object ins not subsriptable it means it cannot be sliced or indexed to find a corresponding value. Yet, here the whole point is to use indexing to assign the year and as a result find the committed prison breaks in that year. Any help please?(my code below) (https://app.dataquest.io/jupyter/notebooks/notebook/Untitled.ipynb?kernel_name=python3)

Hi @henry.vigneron

Is attempts_per_year a list of list setup something like this [ [1986,0] , [1987,0] …]

Someone else had this same error code:

Hi @Casandra_Hayward .

Yes - attempts_per_year is supposed to look like that, but I can’t update the list.

If i used attempts_per_year.append (y_somethingsomething) , would it work?

I’m not sure how to get past this issue as I had a look at other people’s code and they wrote the same thing but without issues.

Thanks,
Henry

@henry.vigneron

Can you rerun all cells in your jupyter notebook?

If that does not resolve it, can you upload your notebook so we can see all the code and see if some other code is causing the error?

@Casandra_Hayward , I created a v2 without the descriptor text.

Still didn’t fix the issue - here is my code.
Guided Project_ Prison Break.tar (654.5 KB)

@henry.vigneron
I will take a look!

@henry.vigneron
I could not open the .tar file. Can you upload the .ipynb file?

Here is a link to an article explaining how to upload the .ipynb

1 Like

prison_break_v2.ipynb (133.5 KB)

Here it is @Casandra_Hayward , Thanks!

Click here to view the jupyter notebook file in a new tab

@henry.vigneron

attempts_per_year is a list [1971, 1972]
your attempts_per_year should be [ [1971,0], [1980,0] …]

Check the instructions for the step after you created attempts_per_year. You should have a step to add 0 to your attempts_per_year to create a list of list [ [1981,0], [1984,0], 1987,0] …]

@henry.vigneron

Try to redo this instruction from the lesson

Guided Project: Prison Break — Attempts Per Year I | Dataquest

@henry.vigneron

The problem is between line 55 and line 56. You need to add a years [ ] list. Copy the code given in the guided project

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

This will create your years list

Then you will create attempts_per_year to look like [<year>, 0]]

attempts_per_year = [ ]
for y in years:
attempts_per_year.append([y, 0])

I see what you were doing now from prior code
attempts_per_year = [ ]
for y in range(min_year, max_year + 1):
attempts_per_year.append(y)

print (attempts_per_year)

Yes, you could change attempts_per_year.append([y,0]) and get same result

Instead of creating a years list, you looped through a range (min_year, max_year+1)