Guided Project: Prison Break - Slide 10

Screen Link:
https://app.dataquest.io/c/115/m/610/guided-project%3A-prison-break/10/attempts-per-year-ii

My Code:

My code:

for row in data:
    for ya in attempts_per_year:  
        if row[0] == ya[0]:
            ya[1] += 1

print(attempts_per_year)

What I expected to happen:

[[1971, 1], [1972, 0], [1973, 1], [1974, 0], [1975, 0], [1976, 0], [1977, 0], [1978, 1], [1979, 0], [1980, 0], [1981, 2], [1982, 0], [1983, 1], [1984, 0], [1985, 2], [1986, 3], [1987, 1], [1988, 1], [1989, 2], [1990, 1], [1991, 1], [1992, 2], [1993, 1], [1994, 0], [1995, 0], [1996, 1], [1997, 1], [1998, 0], [1999, 1], [2000, 2], [2001, 3], [2002, 2], [2003, 1], [2004, 0], [2005, 2], [2006, 1], [2007, 3], [2008, 0], [2009, 3], [2010, 1], [2011, 0], [2012, 1], [2013, 2], [2014, 1], [2015, 0], [2016, 1], [2017, 0], [2018, 1], [2019, 0], [2020, 1]]

What actually happened:

[[1971, 1], [1972, 0], [1973, 1], [1974, 0], [1975, 0], [1976, 0], [1977, 0], [1978, 1], [1979, 0], [1980, 0], [1981, 2], [1982, 0], [1983, 1], [1984, 0], [1985, 2], [1986, 3], [1987, 1], [1988, 1], [1989, 2], [1990, 1], [1991, 1], [1992, 2], [1993, 1], [1994, 0], [1995, 0], [1996, 1], [1997, 1], [1998, 0], [1999, 1], [2000, 2], [2001, 3], [2002, 2], [2003, 1], [2004, 0], [2005, 2], [2006, 1], [2007, 3], [2008, 0], [2009, 3], [2010, 1], [2011, 0], [2012, 1], [2013, 2], [2014, 1], [2015, 0], [2016, 1], [2017, 0], [2018, 1], [2019, 0], [2020, 1]]

So my issue is that the instruction in the tasks says the following.

Use indexing to assign the year in ya to y.

and the suggested solution has an extra line of code compared to my code.

for row in data:
    for ya in attempts_per_year:
        y = ya[0]
        if row[0] == y:
            ya[1] += 1
            
print(attempts_per_year)

I dont understand the purpose of why I should create the variable y = ya[0] when I can just write
if row[0] == ya[0]:.
to achieve the same result. What is the purpose of y=ya[0]?

The purpose is to help with readability. In your version of the code, readers have to juggle two different lists simultaneously, in the provided version, they can understand y and then forget about where it came from.

It’s all the same, though. Your solution is fine.