Update list at index 3 with new value

Viewed 44

Greeting everyone. New user of this Stack Overflow resource. I have code I'm developing that requires me to capture some faculty data into a list, update that list then merge with another list and ftp a csv file. First things first.

I created an empty list

records: List[EmptyRecord] = []

and using

records.extend(faculty_records)

now have a list of faculty data. The email address is at index 3.

I have a doc string SQL statement GET_MAIL that will return the email address I need to update the value at index 3 in faculty_records. I think I need some sort of

records.insert(3, '{email address}')

inside a while loop for all the values in faculty_records.

I have username at index 2 and ID at index 4 in the list to match which address to update. It's Peoplesoft data so ID in the list has to match the emplid from the SQL results.

Can someone assist in getting my pseudocode into python?

Once I get the values updated I need to merge with my student data list, which should be as easy as.

records.extend(student_records) 

and send both student and faculty data to a vendor.

1 Answers

insert() adds a new element at that index, shifting all the following elements over to make room, it doesn't replace. Just use ordinary assignment to replace an element.

Loop through the records with a for loop to find the record with the username you want to update. Then assign to element 3 to update the email.

for record in records:
    if record[2] == username_to_update:
        record[3] = new_email
        break
Related