10. LISTS, TUPLES, AND DICTIONARIES

These free B.Pharm notes on python lists tuples and dictionaries cover chapter 10 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.

Read the following document for full information

Overview of python lists tuples and dictionaries

These notes begin with data structures, their linear and non-linear types, common operations and advantages. They then explain Python lists, tuples and dictionaries one by one, covering the characteristics, internal concept, operations, worked examples, advantages and disadvantages of each, using drug names and patient records as examples.

Key points on python lists tuples and dictionaries

  • A data structure is a systematic method of arranging and storing information in memory so that data can be retrieved, updated and processed efficiently.
  • A stack follows the LIFO (Last In, First Out) principle, while a queue follows the FIFO (First In, First Out) principle.
  • A list is ordered, mutable, dynamic in size, allows duplicates and can hold mixed data types; internally Python builds lists as dynamic arrays.
  • A tuple is ordered but immutable, so its elements cannot be changed after creation; it offers only the count() and index() methods.
  • A dictionary stores data as key-value pairs with unique, immutable keys, is built on hash tables and gives fast lookup in O(1) average time.

Relevance to pharmacy practice

Pharmacy data such as drug names, fixed dosage values and patient records fit naturally into lists, tuples and dictionaries. Knowing which structure to choose helps a pharmacist or researcher store, update and look up such information quickly and protect fixed data from accidental changes.

Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.

Frequently asked questions on python lists tuples and dictionaries

What is the difference between a list and a tuple in Python?

A list is mutable, so its elements can be added, removed or changed, whereas a tuple is immutable and cannot be altered once created. Tuples are therefore faster and use less memory.

Why can a tuple be used as a dictionary key but a list cannot?

Dictionary keys must be of an immutable type. A tuple is immutable, so it can serve as a key, while a list is mutable and cannot.

How is a value added or updated in a Python dictionary?

Assigning dict[key] = value creates a new key-value pair if the key does not exist, or updates the stored value if the key already exists.

Quick revision checklist

Use this self-test after reading the chapter on python lists tuples and dictionaries. If you can do all of the following without looking at your notes, you are ready for the exam.

  • I can explain: linear and non-linear data structures
  • I can explain: the five common operations on data structures
  • I can explain: characteristics of Python lists
  • I can explain: why tuples are faster than lists
  • I can explain: how dictionaries use key-value pairs

Study and exam tips

Start by reading the chapter once for the overall idea, then revise python lists tuples and dictionaries using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.

For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise python lists tuples and dictionaries again a day later and again a week later, because spaced revision improves long-term memory.

This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.

Related notes: 12. INTRODUCTION TO NUMPY ARRAYS AND BASIC OPERATIONS USING NUMPY, 13. READING AND WRITING CSV FILES.

Next: 11. INDEXING AND SLICING LISTS, BASIC OPERATIONS ON LISTS AND DICTIONARIES, STRING MANIPULATION TECHNIQUES. Back to the Basics of Python Programming for Pharmaceutical Sciences category.