Mohamed Essam teaches about various Python data structures including strings, lists, tuples, sets, and dictionaries. Some key points:
- Lists are ordered and changeable collections that can contain elements of different data types and allow duplicates. They use indexes to access elements.
- Tuples are ordered and unchangeable collections that can contain duplicates. They have fewer methods than lists.
- Sets are unordered and unindexed collections that do not allow duplicates. Items cannot be accessed by index and sets cannot be changed after creation, but new items can be added.
- Dictionaries store elements in key-value pairs and are ordered, changeable collections that do not allow duplicate keys. Items
2. Data Structures
● Every child knows that one can – at least beyond a certain number –
find things much easier if one keeps order. We humans understand by
keeping things in order that we separate the things that we possess
into categories and assign fixed locations to these categories that we
can remember.
● We may simply throw socks into a drawer, but for other things like
DVDs it is best to sort them beyond a certain number so that we can
quickly find every DVD.
5. Strings
● A string is a sequence of characters starts from 0
○ We can get any single character in a string using
An index specified in a square brackets
M i l e r
Name=“Miler”
len(Name)
6. Python Collections (Arrays)
● There are four collection data types in the Python programming
language:
○ List is a collection which is ordered and changeable. Allows duplicate
members.
○ Tuple is a collection which is ordered and unchangeable. Allows duplicate
members.
○ Set is a collection which is unordered and unindexed. No duplicate
members.
○ Dictionary is a collection which is ordered* and changeable. No duplicate
members.
7. Python Lists
● Lists are used to store multiple items in a single variable.
● Lists are one of 4 built-in data types in Python used to store
collections of data, the other 3 are Tuple, Set, and Dictionary, all with
different qualities and usage.
● Lists are created using square brackets:
8. Python Lists
● Is a python list a linked list ?
○ No, it’s a dynamic array it allocates space as needed, whenever it
gets ‘full’ it allocates double the space and copies over the data
from the smaller array. It also shrinks when it doesn’t need to
store as much data.
9. List Items
● List items are ordered, changeable, and allow duplicate values.
● List items are indexed, the first item has index [0], the second item
has index [1] etc.
10. List are ordered
● When we say that lists are ordered, it means that the items have a
defined order, and that order will not change.
● If you add new items to a list, the new items will be placed at the end
of the list.
11. List are changeable
● The list is changeable, meaning that we can change, add, and remove
items in a list after it has been created.
12. List Items - Data Types
● List items can be of any data type:
● A list can contain different data types:
● A list with strings, integers and boolean values:
14. Tuple
● Tuples are used to store multiple items in a single variable.
● Tuple is one of 4 built-in data types in Python used to store
collections of data, the other 3 are List, Set, and Dictionary, all with
different qualities and usage.
● A tuple is a collection which is ordered and unchangeable.
● Tuples are written with round brackets.
16. Python Sets
● Sets are used to store multiple items in a single variable.
● Set is one of 4 built-in data types in Python used to store collections
of data, the other 3 are List, Tuple, and Dictionary, all with different
qualities and usage.
● A set is a collection which is both unordered and unindexed.
● Sets are written with curly brackets.
17. Python Sets
● You cannot access items in a set by referring to an index or a key.
● But you can loop through the set items using a for loop, or ask if a
specified value is present in a set, by using the in keyword.
● Once a set is created, you cannot change its items, but you can add
new items.
● To add one item to a set use the add() method.
18. Python Sets
● To remove an item in a set, use the remove(), or the discard() method.
19. Dictionary
● Dictionaries are used to store data values in key:value pairs.
● A dictionary is a collection which is ordered*, changeable and does
not allow duplicates.
● We use it to create JSON APIS.
20. Dictionary
● Accessing Items
○ You can access the items of a dictionary by referring to its key
name, inside square brackets:
21. Dictionary
● Get Keys
○ The keys() method will return a list of all the keys in the
dictionary.
23. Dictionary
● Adding Items
○ Adding an item to the dictionary is done by using a new index key
and assigning a value to it:
24. Dictionary
● Removing Items
○ There are several methods to remove items from a dictionary:
○ The pop() method removes the item with the specified key name:
○ The popitem() method removes the last inserted item (in versions before 3.7, a
random item is removed instead):
○ The del keyword removes the item with the specified key name:
○ The clear() method empties the dictionary:
25. Pandas data frame
● The Pandas DataFrame is a structure that contains two-dimensional data and its
corresponding labels. DataFrames are widely used in data science, machine learning,
scientific computing, and many other data-intensive fields. DataFrames are similar to
SQL tables or the spreadsheets that you work with in Excel or Calc.