obi79
February 10, 2024, 1:47am
1
[[‘Marina Allison’, ‘27’, ‘31.1’, ‘$7010.0’], [‘Markus Valdez’, ‘30’, ‘22.4’, ‘$4050.0’], [‘Connie Ballard’, ‘43’, ‘25.3’, ‘$12060.0’], [‘Darnell Weber’, ‘35’, ‘20.6’, ‘$7500.0’], [‘Sylvie Charles’, ‘22’, ‘22.1’, ‘$3022.0’], [‘Vinay Padilla’, ‘24’, ‘26.9’, ‘$4620.0’], [‘Meredith Santiago’, ‘51’, ‘29.3’, ‘$16330.0’], [‘Andre Mccarty’, ‘19’, ‘22.7’, ‘$2900.0’], [‘Lorena Hodson’, ‘65’, ‘33.1’, ‘$19370.0’], [‘Isaac Vu’, ‘34’, ‘24.8’, ‘$7045.0’]]
How do I create a copy of this list where I have removed the last name in each record? I want to have the same list with just the first name in the name object…
Related to https://www.codecademy.com/paths/bi-data-analyst/tracks/dsf-python-fundamentals-for-data-science-part-ii/modules/dsf-python-strings/projects/ds-python-strings-project
What have you tried? Please post your formatted code.
obi79
February 10, 2024, 11:01pm
4
list_with_first_name =
for record in records:
list_with_first_name.append(medical_records_clean.split()[0])
print(list_with_first_name)
name_num = [['Marina Allison', '27', '31.1', '$7010.0'], ['Markus Valdez', '30', '22.4', '$4050.0'],['Connie Ballard', '43', '25.3', '$12060.0'], ['Darnell Weber', '35', '20.6', '$7500.0'], ['Sylvie Charles', '22', '22.1', '$3022.0'], ['Vinay Padilla', '24', '26.9', '$4620.0'], ['Meredith Santiago', '51', '29.3', '$16330.0'], ['Andre Mccarty', '19', '22.7', '$2900.0'], ['Lorena Hodson', '65', '33.1', '$19370.0'], ['Isaac Vu', '34', '24.8', '$7045.0']]
first_last = []
for i in range(len(name_num)):
name = name_num[i][0]
first_last.append(name.split())
name_num[i][0] = first_last[i][0]
print(name_num)
system
Closed
March 23, 2024, 3:25pm
7
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.