Problem: I would like it to know that the variable in a for loop is a temporary variable? or changing the variable will change the data as well. Since after writing the below code and making changes to 'ele' in the for loop is changing the lists in 'data'.
for ele in data[1:]:
birthday = ele[2]
try:
birthday = birthday.split('-')
birth_year = birthday[0]
birth_year = int(birth_year)
except:
birth_year = 0
ele.append(birth_year)
print(data)
Data:
[['last_name', 'first_name', 'birthday', 'gender', 'type', 'state', 'party'],
['Bassett', 'Richard', '1745-04-02', 'M', 'sen', 'DE', 'Anti-Administration'],
['Bland', 'Theodorick', '1742-03-21', '', 'rep', 'VA', ''],
['Burke', 'Aedanus', '1743-06-16', '', 'rep', 'SC', ''],
['Carroll', 'Daniel', '1730-07-22', 'M', 'rep', 'MD', ''],
['Clymer', 'George', '1739-03-16', 'M', 'rep', 'PA', ''],
['Contee', 'Benjamin', '', 'M', 'rep', 'MD', ''],
['Dalton', 'Tristram', '1738-05-28', '', 'sen', 'MA', 'Pro-Administration'],
['Elmer', 'Jonathan', '1745-11-29', 'M', 'sen', 'NJ', 'Pro-Administration'],
['Few', 'William', '1748-06-08', 'M', 'sen', 'GA', 'Anti-Administration']]