Stuck on strptime problem

Screen Link:

My Code:


for row in potus: 
    appt_start = row[2]
    appt_start = dt.datetime.strptime(appt_start, "%m/%d/%y %H:%M")
    row[2] = appt_start

What I expected to happen:

If we are looking at the third column, how come its row[2]?
Shouldn’t it be column[2]?



Click here to open the screen in a new tab.

Hi @laurenk9304

Below is the first 3 rows of potus

[['Joshua T. Blanton',
  '2014-12-18T00:00:00',
  datetime.datetime(2015, 1, 6, 9, 30),
  '1/6/15 23:59',
  '',
  'potus',
  'west wing',
  'JointService Military Honor Guard'],
 ['Jack T. Gutting',
  '2014-12-18T00:00:00',
  datetime.datetime(2015, 1, 6, 9, 30),
  '1/6/15 23:59',
  '',
  'potus',
  'west wing',
  'JointService Military Honor Guard'],
 ['Bradley T. Guiles',
  '2014-12-18T00:00:00',
  datetime.datetime(2015, 1, 6, 9, 30),
  '1/6/15 23:59',
  '',
  'potus',
  'west wing',
  'JointService Military Honor Guard']

When you say

for row in potus:

it selects the below list and saves it to the iterating variable called row

['Joshua T. Blanton',
  '2014-12-18T00:00:00',
  datetime.datetime(2015, 1, 6, 9, 30),
  '1/6/15 23:59',
  '',
  'potus',
  'west wing',
  'JointService Military Honor Guard'],

then the next line says row[2] , it selects the item at index 3 (remember indexing starts from 0)

So you are actually selecting the element in 3rd column or column[2]
Don’t get confused with the variable name we have given as row

I hope this helps

Thanks for your help @jithins123 ! Oh okay, so we are looking at it in the format below,

['Joshua T. Blanton',
  '2014-12-18T00:00:00',
  datetime.datetime(2015, 1, 6, 9, 30),
  '1/6/15 23:59',
  '',
  'potus',
  'west wing',
  'JointService Military Honor Guard']

And we are not looking at the actual Potus table, correct? So that’s why we are indexing from the format above so its row[2]?

1 Like

You are looking at it as a table like it is given on the screen. So it is represented as a list of list.

And you are going through the list row by row, not column by column.

That is why we gave the name row to the iterating variable.

So in each iteration you are selecting a whole row.

Once you have selected that, your task now is to find the element you want from that row.

How can you select an element in a list? By saying list[index]

But here the list is called row. So you say row[2]

Makes sense?

Please have a look at list of list mission again if it isnt clear.

3 Likes

Hi @laurenk9304,
Did this sort out your doubt?

1 Like

yes I did. Thank you!

1 Like