In [1]:
# List of Integers
patient_ages = [25, 30, 45, 50, 60]
last_age = patient_ages.pop()
print("Popped age:", last_age)
print("Updated list:", patient_ages)
age_at_index_2 = patient_ages.pop(2)
print("Popped age at index 2:", age_at_index_2)
print("Updated list:", patient_ages)
Popped age: 60 Updated list: [25, 30, 45, 50] Popped age at index 2: 45 Updated list: [25, 30, 50]
In [2]:
# List of Strings
patient_names = ["Alice", "Bob", "Charlie", "Diana", "Eve"]
last_name = patient_names.pop()
print("Popped name:", last_name)
print("Updated list:", patient_names)
name_at_index_1 = patient_names.pop(1)
print("Popped name at index 1:", name_at_index_1)
print("Updated list:", patient_names)
Popped name: Eve Updated list: [''''Alice'''', ''''Bob'''', ''''Charlie'''', ''''Diana''''] Popped name at index 1: Bob Updated list: [''''Alice'''', ''''Charlie'''', ''''Diana'''']
In [3]:
import pprint
# List of dictionaries
patient_records = [
{"name": "Alice", "age": 25, "condition": "Flu"},
{"name": "Bob", "age": 30, "condition": "Cold"},
{"name": "Charlie", "age": 45, "condition": "Asthma"},
{"name": "Diana", "age": 50, "condition": "Diabetes"},
{"name": "Eve", "age": 60, "condition": "Hypertension"}
]
last_record = patient_records.pop()
print("Popped record:")
pprint.pp(last_record)
print("Updated list:")
pprint.pp(patient_records)
record_at_index_0 = patient_records.pop(0)
print("Popped record at index 0:")
pprint.pp(record_at_index_0)
print("Updated list:")
pprint.pp(patient_records)
Popped record: {''''name'''': ''''Eve'''', ''''age'''': 60, ''''condition'''': ''''Hypertension''''} Updated list: [{''''name'''': ''''Alice'''', ''''age'''': 25, ''''condition'''': ''''Flu''''}, {''''name'''': ''''Bob'''', ''''age'''': 30, ''''condition'''': ''''Cold''''}, {''''name'''': ''''Charlie'''', ''''age'''': 45, ''''condition'''': ''''Asthma''''}, {''''name'''': ''''Diana'''', ''''age'''': 50, ''''condition'''': ''''Diabetes''''}] Popped record at index 0: {''''name'''': ''''Alice'''', ''''age'''': 25, ''''condition'''': ''''Flu''''} Updated list: [{''''name'''': ''''Bob'''', ''''age'''': 30, ''''condition'''': ''''Cold''''}, {''''name'''': ''''Charlie'''', ''''age'''': 45, ''''condition'''': ''''Asthma''''}, {''''name'''': ''''Diana'''', ''''age'''': 50, ''''condition'''': ''''Diabetes''''}]