---
# System prepended metadata

title: 'Summary of Week Eight''s Activities @BLockfuse Labs: Tuple Set and Dictionary in Python'

---

# Summary of Week Eight's Activities @BLockfuse Labs: Tuple Set and Dictionary in Python

**Tuples:** 
A tuple in python is an ordered and immutable collection of items. This means that once a tuple is created, it's elements cannot be updated (you can neither add to it or remove from it). Tuples can store items of different data types, even other tuples which means that a tuple is considered heterogeneous because it can store elements of different data types within a single sequence. Unlike some other data structures or arrays in statically-typed languages that require all elements to be of the same type (homogeneous).

Tuple are defined by enclosing comma-separated values within parenthesis(). Also, individual items within a tuple can be accessed using zero-based integer indices(index of the item). 
A tuple contains multiple variables that can be iterated upon. That is, repeatedly accessing elements within a collection or sequence, to perform operations on each element. 

Examples of a tuple: 
```
an_empty_tuple = ()
one_item_tuple = (2,)
mix_item_tuple = (1, "hello", True, 3.14, [], (),{})
```

**Set** 
Set is a collection of unique  items/elements/objects which are unordered and sets are mutable. Set in Python is defined using the ***curly brackets*** {} or ***set constructor***. Set and dictionary use the curly brackets {} to store data. But while sets store individual elements; dictionaries store key-value pairs.  

Due to the unordered nature of sets, they cannot be accessed using indexing and it does not support list data because it is unhashable. Python sets are unhashable because they are mutable. You can add or remove elements from a set, which changes its contents. Because the contents can change, a consistent hash value cannot be guaranteed, preventing sets from being elements within other sets or keys in dictionaries.
Duplicates items in sets are automatically removed when creating or adding to a set.

Example of set: 
```
my_set = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
"Saturday", "Sunday", "Monday", "Tuesday"}
print({my_set})
```
Output for the above example will be a set of only 7 items because set does not keep duplicate items. 

Below is an example of some set methods:
![set-method](https://hackmd.io/_uploads/HkxAVe6vgl.png)


**Dictionary**
Python dictionary is an ordered, data structure that stores the value in key: value pairs. Values in a dictionary can be of any data type and can be duplicated, whereas keys can't be repeated and must be immutable.
The dict() constructor is used to make a dictionary.

*Example of a dictionary*: 

student_info = {"name" : "Tom", "Department" : "Computer", "Registration" : 2014,}
print(student_info)

![dictionary](https://hackmd.io/_uploads/BJeCAkTPxl.png)

*There are different dictionary methods, below are some used examples:*

![dict-method](https://hackmd.io/_uploads/SylzFl6vxg.png)

*copy():* Returns a shallow copy of the dictionary.

*get(key, default):* Returns the value of a key if it exists, otherwise returns the default value.

*items()*:Returns a view object that displays a list of a dictionary's key-value pairs.

*del:* Removes an item by key.

*pop():* Removes an item by key and returns its value.

*clear():* Empties the dictionary.

*popitem():* Removes and returns the last key-value pair

*len(dict):*Returns the number of key-value pairs in a dictionary.

**Conclusion**
"Python dictionaries provide a wide range of methods for key-value management. Whether retrieving, updating, or deleting data, these methods offer efficient ways to manipulate dictionaries in Python".  (https://dev.to/usooldatascience/a-quick-guide-to-python-dictionary-methods-with-examples-2gfb).
List, Tuples, Disctionary and set are designed to store collections of items, making them suitable for managing different types of data and they are all iterable, meaning their elements can be processed sequentially using constructs like for loops.