Lists, Tuples & Dictionaries in Python for Pharmacy Students (Patient Records, Drug Data & Dose Management)
Data structures in Python are used to store and organize data efficiently. In pharmaceutical sciences, they are essential for handling patient records, drug information, and dosage data.
๐ท What are Data Structures?
Data structures allow storing multiple values in a single variable.
๐ท Lists (Mutable Data Structure)
A list is used to store multiple values in a single variable. Lists are mutable, meaning they can be changed.
doses = [500, 650, 400] print(doses)
๐ Pharma Example
patient_doses = [500, 500, 650, 400]
print("Dose list:", patient_doses)
Used for storing multiple patient doses.
๐ท Tuples (Immutable Data Structure)
A tuple is similar to a list but cannot be changed once created.
drug_info = ("Paracetamol", 500, "Tablet")
๐ Pharma Example
Used for fixed drug properties like composition.
๐ท Dictionaries (Key-Value Pair)
A dictionary stores data in key-value pairs.
patient = {
"name": "John",
"age": 45,
"drug": "Aspirin"
}
๐ Pharma Example
Represents patient records in clinical settings.
๐ท Difference Between List, Tuple & Dictionary
| Feature | List | Tuple | Dictionary |
|---|---|---|---|
| Mutable | Yes | No | Yes |
| Structure | Ordered | Ordered | Key-Value |
| Example | [500, 650] | (500, 650) | {“dose”:500} |
๐ง Memory Trick
- List โ Changeable (Multiple doses)
- Tuple โ Fixed (Drug properties)
- Dictionary โ Patient record (Key-Value)
๐งช Practice Exercise
Create:
- List of 5 patient doses
- Tuple for drug information
- Dictionary for patient record
๐งช Mini Project
Create a simple patient data system:
patient = {
"name": "Alice",
"age": 30,
"dose": [500, 650]
}
print(patient)
๐ MCQs
- Which data structure is mutable?
a) Tuple
b) List
c) String
d) None
Answer: b - Which is immutable?
a) List
b) Dictionary
c) Tuple
d) Set
Answer: c - Dictionary stores data as:
a) List
b) Tuple
c) Key-Value
d) Array
Answer: c
โ FAQs
Why are data structures important in pharmacy?
They help in organizing patient data, drug records, and dosage information efficiently.
When should we use tuple?
When data should not be changed, such as drug composition.
๐ฅ Download Pharma Data Practice Exercises
Includes patient datasets and coding problems.
โก Next Topic: Indexing & Slicing in Python โ
Recommemded readings
- Lists, Tuples & Dictionaries (with pharma data examples) : Current page
- Indexing, Slicing & Operations (Extracting patient/drug data)
- NumPy Arrays (Dose calculations, concentration arrays)
- CSV File Handling (Reading ADR datasets, writing reports)
- Understanding Healthcare Datasets (Structure, columns, patient data interpretation)
- Data Access & Manipulation (Filter, select, basic operations)
Question Bank Unit 3: Data Structures & File Handling
For more details: Basics of Python Programming for Pharmaceutical Sciences