Lists, Tuples, Sets and Dictionary - Formula Sheet
Formula Sheet
This formula sheet lists key methods, operators, and functions used when working with Lists, Tuples, Sets, and Dictionaries in Python, along with their parameters and descriptions.
| Category | Syntax / Method | Description and Symbol Definitions |
|---|---|---|
| Lists | list_var = [e1, e2, ...] | Creates a mutable, ordered sequence where e1, e2 are elements of any data type. |
| Lists | list_var.append(x) | Appends element x to the end of the list. |
| Lists | list_var.extend([x1, x2, ...]) | Appends multiple elements x1, x2, ... from an iterable to the end of the list. |
| Lists | list_var.insert(i, x) | Inserts element x at the specified index position i. |
| Lists | list_var.remove(x) | Removes the first occurrence of the element value x from the list. |
| Lists | list_var.pop(i) | Removes and returns the element at the index i. If i is omitted, removes the last element. |
| Lists | list_var.clear() | Deletes all elements from the list, leaving it empty. |
| Lists / Tuples | len(seq) | Returns the total number of elements in the sequence seq. |
| Lists / Tuples | seq[start:stop:step] | Slices the sequence from index start up to but not including index stop, moving forward by step. |
| Tuples | tup_var = (e1, e2, ...) | Creates an immutable, ordered sequence where e1, e2 are elements. |
| Tuples | singleton = (x,) | Creates a tuple containing a single element x. The trailing comma is mandatory. |
| Sets | set_var = {e1, e2, ...} | Creates an unordered collection of unique elements where e1, e2 are unique items. |
| Sets | set_A | set_B | Union: Returns a set containing all unique elements from set_A and set_B. Alternatively, use set_A.union(set_B). |
| Sets | set_A & set_B | Intersection: Returns a set containing elements common to both set_A and set_B. Alternatively, use set_A.intersection(set_B). |
| Sets | set_A - set_B | Difference: Returns a set containing elements that are in set_A but not in set_B. Alternatively, use set_A.difference(set_B). |
| Sets | set_A ^ set_B | Symmetric Difference: Returns a set containing elements in either set_A or set_B, but not both. Alternatively, use set_A.symmetric_difference(set_B). |
| Dictionaries | dict_var = {k1: v1, k2: v2, ...} | Creates an associative key-value mapping where k1, k2 are unique keys, and v1, v2 are their respective values. |
| Dictionaries | dict_var[key] = value | Adds or updates the key with the specified value in the dictionary. |
| Dictionaries | del dict_var[key] | Deletes the key-value pair corresponding to key from the dictionary. |
| Dictionaries | dict_var.clear() | Deletes all key-value pairs from the dictionary. |
More for this chapter
Book Back Questions12 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Science
View all
1 Function
2 Data Abstraction
3 Scoping
4 Algorithmic Strategies
5 Python -Variables and Operators
6 Control Structures
7 Python functions
8 Strings and String manipulation
10 Python Classes and objects
11 Database Concepts
12 Structured Query Language (SQL)
13 Python and CSV files
14 Importing C++ programs in Python.
15 Data manipulation through SQL
16 Data visualization using pyplot: line chart, pie chart and bar chart