In [1]:
#Removing Integers from a List
patient_ages = [25, 30, 45, 30, 50]
patient_ages.remove(30)
print(patient_ages)
[25, 45, 30, 50]
In [2]:
#Removing Strings from a List
patient_names = ["Alice", "Bob", "Charlie", "Bob", "Diana"]
patient_names.remove("Bob")
print(patient_names)
[''''Alice'''', ''''Charlie'''', ''''Bob'''', ''''Diana'''']
In [3]:
import pprint
#Removing Dictionaries from a List
patient_records = [
{"name": "Alice", "age": 25, "condition": "Flu"},
{"name": "Bob", "age": 30, "condition": "Cold"},
{"name": "Charlie", "age": 45, "condition": "Allergy"},
{"name": "Bob", "age": 30, "condition": "Cold"}
]
record_to_remove = {"name": "Bob", "age": 30, "condition": "Cold"}
patient_records.remove(record_to_remove)
pprint.pp(patient_records)
[{''''name'''': ''''Alice'''', ''''age'''': 25, ''''condition'''': ''''Flu''''}, {''''name'''': ''''Charlie'''', ''''age'''': 45, ''''condition'''': ''''Allergy''''}, {''''name'''': ''''Bob'''', ''''age'''': 30, ''''condition'''': ''''Cold''''}]