In [1]:
#Extending a List with Integers
patient_ages = [25, 30, 45]
new_ages = [50, 60, 70]
patient_ages.extend(new_ages)
print(patient_ages)
[25, 30, 45, 50, 60, 70]
In [2]:
#Extending a List with Strings
patient_names = ["Alice", "Bob", "Charlie"]
new_names = ["David", "Eva", "Frank"]
patient_names.extend(new_names)
print(patient_names)
[''''Alice'''', ''''Bob'''', ''''Charlie'''', ''''David'''', ''''Eva'''', ''''Frank'''']
In [3]:
import pprint
#Extending a List with Dictionaries
patient_records = [
{"name": "Alice", "age": 25, "condition": "Diabetes"},
{"name": "Bob", "age": 30, "condition": "Hypertension"}
]
new_records = [
{"name": "Charlie", "age": 45, "condition": "Asthma"},
{"name": "David", "age": 50, "condition": "Heart Disease"}
]
patient_records.extend(new_records)
pprint.pp(patient_records)
[{''''name'''': ''''Alice'''', ''''age'''': 25, ''''condition'''': ''''Diabetes''''}, {''''name'''': ''''Bob'''', ''''age'''': 30, ''''condition'''': ''''Hypertension''''}, {''''name'''': ''''Charlie'''', ''''age'''': 45, ''''condition'''': ''''Asthma''''}, {''''name'''': ''''David'''', ''''age'''': 50, ''''condition'''': ''''Heart Disease''''}]