0% found this document useful (0 votes)
8 views

Lecture 4

The document discusses different data structures in Python including lists, tuples, dictionaries, and sets. It provides details on defining, accessing, modifying, and using each structure. Key points covered include properties like mutability, uniqueness of elements, indexing, slicing, and common usage scenarios for each type of data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture 4

The document discusses different data structures in Python including lists, tuples, dictionaries, and sets. It provides details on defining, accessing, modifying, and using each structure. Key points covered include properties like mutability, uniqueness of elements, indexing, slicing, and common usage scenarios for each type of data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Data Structures

and Sequences
Summarize

► Assign input value from keyboard


► Numbers operators
► String operators
► String slicing
► String format
► Boolean operator and convert other datatype to bool.
► If, elif, else statement.
► Loops:
► While loops
► For loops
Outline

► List
► Tuple
► Dict
► Set
List

► Lists are variable-length and their contents can be modified in-


place.
► Define using square brackets [] or using the list type function.
► Add and remove element from a list
► Concatenating, combining and filtering lists
► Sorting list
► Slicing list
► Built-in Sequence Functions
Tuple

► A tuple is a fixed-length, immutable sequence of Python objects.


► Create with a comma-separated sequence of values.
► Elements can be accessed with square brackets [] as with most
other sequence types, sequences are 0-indexed in Python
Dict

► It is a flexibly sized collection of key-value pairs, where key and


value are Python objects.
► One approach for creating one is to use curly braces {} and colons
to separate keys and values
Set

► A set is an unordered collection of unique elements.


► A set can be created in two ways: via the set function or via a set
literal with curly braces {}.
List, Set, and Dict Comprehensions

► Filter list
► Flatten nested list
► Using for loops
Recap
List Tuple Dict Set

Dict = {"name":'data',
Sample List = [10,'a',25] tuple = (2, 5, 'b') Set = {1, 3, 's'}
"member":3}
Set elements can't be
Accessable List[0] tuple[0] Dict["name"]
indexed
Can't contain duplicate keys,
Uniques but can contain duplicate
NO NO values YES
Mutable YES NO YES YES
Slicable List[0:1] tuple[0:1] NO NO

-Logical association beetween -Membership testing


-Data doesn't need random
key:value and the elimination of
access -Use when data cannot
Usage -Fast lookup base on custom duplicate entries.
-Simple, iterable collections change.
key. -Uniqueness for the
that is modified frequenly
-Data constanly modified elements

You might also like