LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Assignment Question

Hello,
I had a question in the “Cleaning and Preparing Data In Python” Mission on Page 4.
URL:Learn data science with Python and R projects

for row in moma:
nationality=row[2]
nationality=nationality.replace('(','')
nationality=nationality.replace(')','')
row[2]=nationality

Question 1: How would one say the last line, verbally? Would it be:
“Nationality is assigned to list index 2”
“Nationality is assigned to list with index 2”
Nationality is assigned to row index 2" etc.

Question 2:
Again, for the last line, what is row[2] and nationality considered to be? I know we assign things to variables, right to left (i.e. x=5, 5 is assigned to x). row[2] doesn’t strike me as being a variable though.

1 Like

Hi Mike,

nationality is a variable to which we initially assign the value of row[2]. Then later we do some manipulations with this variable and return the resulting value back to row[2].

Since moma here represents a list of lists, row represents one of the lists (let’s say, a sub-list) of this list of lists, and in our for-loop we iterate through all these sub-lists, then row[2] is the third item of a sub-list row, considering that the indexing of Python starts with 0.

Hence as for the last row, I would say that at each iteration of the for-loop, the value of the variable nationality is assigned back to the third item of a list row, which is one of the sub-lists of the list of lists moma.

1 Like

Hi @Elena_Kosourova,
So, to say something like this verbally/to type it to someone, if I’m understanding correctly, would be "Nationality is assigned back to the third item of the list row?"

1 Like

Yes, exactly! This is a correct phrase.

1 Like

Thank you @Elena_Kosourova!

1 Like