data structures in python: List, tuple, set, dictionaries

AshaWankar1 64 views 108 slides Jun 02, 2024
Slide 1
Slide 1 of 108
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108

About This Presentation

This PPT provides various data structures in Python such as lists, tuples, sets, and dictionaries with methods and operations. python, list, list(), data, data structure, dictionary,dictionary(), tuple(), insert, insert(), sorted, sorted(), dict(), del, del(), sum(), sum, len, len(), append, append(...


Slide Content

DATA STRUCTURES IN PYTHON

BY -
MS. A. V. WANKAR
MRS. DIPALI GOSAVI

PREAMBLE

In this teaching material readers will understand:-
1. What are the different data structures in python
2. What are the methods of each data structure.

3. What operations can be performed on each data

structure.

. Applying data structures to solve the problems.

vata structures in Python

COPYRIGHT OFFICE

NEW DELHI

SBATA’STRUCTURES IN PYTHON

1. List

2. Tuple

3. Set

4. Dictionary

lists can be heterogeneous
* a = [hello', example‘, 100, 1234, 2*2]
Lists can be indexed and sliced:
- a[O] -> hello”
* a[:2] -> [hello', 'example']
Lists can be manipulated
* a[2] = a[2] + 23
* a[0:2] = [1,12]
- a[0:0] = |]
elen(a) -> 5

= It is possible to create a new list from another.

" Example:
® A=[1,34.5,’hello’,2+3j]
= B=A # copies all elements of A to B, both points to
same list, Changing one changes the other.
" It is possible to create a list of lists:

" Example:
= List 1= [2, 5, 3]
= List2=[1,34,6]
= List3=[List1,List2]
= Print(List3)# [[2, 5,3],[1,34, 6]

vata structures in Python

VARIETIES (CONT...)

= Alist can be embedded in another list.

" Example:
" A=/1,2,3,4]
= B=[10,20,A,30]
= Print(B) # [10,20,[1,2,3,4],30]
= It is possible to unpack a list within a list using the
* operator.
" Example:
" A=/1, 2, 3,4]
= B=[10,20,*A,30]
HE] = Print(B) # [10,20,1,2,3,4,30]

vata structures in Python

LIST METHODS

=" append(x): append element x at the end of list & does

not return anything. i.e. None is returned
" Syntax: list. append (x)
= Example:

+ # Adds List Element as value of List.
+ List = [Mathematics', 'chemistry', 1997, 2000]
» List.append(20544)

vata structures in Python

" extend(List2): append all items in List2 to list 1, returns
None.

" Syntax: List1.extend(List2)
= Example:

*List1 = [1, 2, 3]
-List2 = [2, 3, 4, 5]

++ Add List2 to List1
-Listl.extend(List2)
-print(List1)

«+ Add List1 to List2 now
“fg ist2.extend(List1)

vata structures in Python

LIST METHODS

= insert(i, x): Insert element x at index i (i should be
within range , otherwise we get Index Error ), returns
None.

" Syntax: list.insert(index, x)

" Example:

-List = Mathematics”, ‘chemistry’, 1997, 2000]
++ Insert at index 2 value 10087

*List.insert(2, 10087)

-print(List)

vata structures in Python

COPYRIGHT

sc

Date 091 4
count(x): Returns total occurrence of element x in List

= Syntax: List.count(x)

=" Example:
-List = [1, 2, 8, 1, 2, 1, 2, 3, 2, 1]
»print(List.count(1))

" index(x) : Returns the index of first occurrence of x
" Syntax: List.index(x[,start][,end])
=" Example:
«List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1]
*print(List.index(2))
“Print(List.index(2,2))
El ?rint(List.index(2,5,9) # it will search in start=5 and end=9-1
€ “es

vata structures in Python

" pop([index]) : Index is not a necessary parameter, if not
mentioned pops and returns element at the last index.

" Syntax: list.pop([index])

" Example:
= List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
= print(List.pop())
= print(List.pop(0))

"= remove(x): remove first occurance of element x from list,
returns None.

= Syntax: list. remove(x)
=" Example:

HE] + List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
remove(3)
ı print(List)

vata structures in Python

COPYRIGHT OFFICE
=ERP-.METHODS

" reverse(): It simply reverses the list, returns None.
= Syntax: List.reverse()

= Example:

= List = (2.3, 4.445, 3, 5.33, 1.054, 2.5]
= List.reverse()
= print(List)

= sort() : Sorts the list in Place

" Syntax: List.sort([key,[Reverse_flag)))

= Example:
= List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
= Print(List.sort())
= #Reverse flag is set True

HE] List.sort(reverse=True)

vata structures in Python

clear(): It simply reverses the list, returns None.
= Syntax: List.clear()
= Example:

" List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
= List.clear()
= print(List}# prints empty list

= copy() : copy elements of List. Returns List
= Syntax: List.copy()

= Example:

" List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]

El L-List. copy()

vata structures in Python

ING ELEMENT USING DEL

del list[index]: Element to be deleted is mentioned using list
name and index. remove by index, not value remove slices from
list (rather than by assigning an empty list)

" Syntax: del list/index] or del list/start_index : end_index]
= Example:

= List =[2.3, 4.445, 3, 5.33, 1.054, 2.5]

= del List/O]

= del List[3:5] # removes elements from index start to end-1

= Print(List)

vata structures in Python

N FUNCTIONS OF LIST

=" sum() : Calculates & Returns sum of all the elements of List.
= Syntax: sum(List)
" Example:

« List =[1, 2, 3, 4, 5]

= print(sum(List))

= Note: Sum is calculated only for Numeric values, elsewise
throws TypeError.

= len() :Calculates & Returns total length of List.
" Syntax: len(list_name)

" Example:

E List ™ [1,.2,-3).1, 2, 1,2,3,2, 1]

print (List)

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF LIST

"= min() : Calculates & Returns minimum of all the elements of
List.

= Syntax: min(List)
" Example:

" List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
= print(min(List))

" max() :Calculates 8 Returns maximum of all the elements of
List.
= Syntax: max(List)

ıple:

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF LIST

= sorted() : returns a sorted list of the specified list.
" Syntax: sorted(list[,key/, Reverse_Flag ] |)
" Example:

" List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]

= l1=sorted(List)

= Print(l1)

" 12=sorted(List, reverse=True)

" Print(l2)

Note: if Reverse_Flag = True then sorts in descending order
atherwise sort in ascending order, by default Reverse_Flag = False.

vata structures in Python

COPYRIGHT
NEW DE

Reg. No.

L() BUILT-IN FUNCTIONS

= This function returns true if all of the items are True (or if
the iterable is empty).

= All can be thought of as a sequence of AND operations on the
provided iterables.
" Syntax: all(list of iterables)
= Example:
= # print (all([True, True, True, True])) # Here all the iterables are

True so all will return True and the same will be printed

= print (all([False, True, True, False])) # False
El print (all([False, False, False])) + False

vata structures in Python

COPYRIGHT
NEW DE
Reg. No.

() BUILT-IN FUNCTIONS

= Returns true if any of the items is True.

= It returns False if empty or all are false. Any can be thought
of as a sequence of OR operations on the provided iterables.

" Syntax: any(list of iterables)
" Example:

= # print (any([False, False, False, False])) # Here all the

iterables are False so any will return False and the same will

be printed

vata structures in Python

COPYRIGHT OFF
NEW DELHI
4761

SOMPREHENSION

= A list comprehension offers an easy way of
creating lists.

It consists of brackets containing expression
followed by a for clause, and zero or more for or if
clause.

=" Used when you want to create a new list based on
the values of an existing list.
=" Syntax:

" Newlist = [expression for item in iterable/ sequence [optional

ind/ or if] ]

vata structures in Python

COMPREHENSION (CONT....)

=" Example:
"A = [0,5,6,3,2,9,8,4]
= B=/]
"foriin A:
= if i>=5:
= B.append(i)

= print(B) # [5,6, 9,8]

= Same can be done in One line using list comprehension

: for x in A if x>=5]
t(Lj#-{9,6, 9, 8]

im Python

COPYRIGHT OFFICE

DB F-SOMPREHENSION (CONT....)

>>> a = [2,4,6]

>>> [3*x for x in a]

[6, 12, 18]

>>> [{x: x**2} for x in a}
[{2: 4}, {4: 16}, {6: 36}]
>>> [[x, x**2] for x in a]

[[2, 4], [4, 16], [6, 36]]

>>> [[x, x**2] for x in a]
me 2! 14, 16], [6, 36
wo = [4, 16], [6, 36]]

2024

COMPREHENSION (CONT....)

cross products:

>>> vecl = [2,4,6]

>>> vec2 = [4,3,-9]

>>> [x*y for x in vecl for y in vec2]
[8,6,-18, 16,12,-36, 24,18,-54]
>>> [ x+y for x in vecl for y in vec2]
[6,5,-7,8,7,-5,10,9,-3]

>>> [vecl[i]*vec2[i] for i in range(len(vec1))]

vata structures in Python

-COMPREHENSIONS

can also use if:

>>> [3*x for x in vec if x > 3]
[12, 18]
>>> [3*x for x in vec if x < 2]

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

“IST COMPREHENSION (CONT....)
>>> a = [(i, j) for i in [1,2] for j in [1,2] if il=j]

>>>print(a)
[ (1,2),(2,1) ]

>>> a=[(i, j, k) for iin [1,2,3] forj in [1, 2, 3] for kin [1,
2, 3] if il=j and j!=k and k!=i]

>>> print(a)

[(1,2,3), (1,3,2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
>>> arr=[[1,2,3,4], [5,6,7,8]]

>>>h=In for ele in arr for n in ele]

2 at(b),,

h 5, 2, + 8]

ES: INTRODUCTION

" A simple ordered sequence of
items.

= Items can be of mixed types, including
collection types.

" tuples are defined using parentheses and
commas.
= Example:

t = (23,‘abc’,4.56,(2,3), xyz’)

" individual members of a tuple are accessed by
using positive and negative index starting with
‘0’ similar to the lists.

Example:
print(t[O]) # prints 23
“ print(t[-1]) # prints ‘xyz’

vata structures in Python

FOPLES: DEFINING TUPLES

=" Using parenthesis to define tuple is optional.
"= Example:
a=10;b=20;c=30
t=a, b,c
or
t=(a, b, c)
print(t)
=" Empty tuple can be created as shown below.
=» Example:
t=()
print(t)#()
= A tuple with single value can be created as..
= Example:
t=(23,)
te: note the comma (,) written after 23. If we
n'tgive this comma then t will be created as a
rmal variable instead of tuple.

im Python

: UNPACKING

" Itis possible to unpack tuples & also lists.
= Example:
a=t[0]
b=t|1]
c=t[2]
(a, b, c)=t
or
a, b, c=t
« Ifthe number of variables are less than the
number of values then we can add an * to the
variable name and the values will be assigned
to the variable as a list:
: Examplel:
= (23, ‘abc’,4.56,(2,3), xyz’)
: a. b, *c)=t
print(c)

: UNPACK CONT..

= Example2:
t = (23, ‘abe’,4.56,(2,3),‘xyz))
(a, *b, c)=t
print(a)#23
Print(b)#[‘abc’,4.56,(2,3)]
print(c)#xyz

" Itis possible to unpack tuple within another
tuple.
= Example:
t1=(100,*t)
print(t1) # (100,23,’abc’,4.56,(2,3),’xyz’)

NEW DELHI

TUPLES} SLICE/CUT OPERATOR ([:])

= We can use cut/slice operator ([:]) with tuples
similar to the lists.
"= Example:
t=(23,45,56.4,3+6j,’abc’)
print(t[2:])#(56.4,3+6j,’abc’)

= We can print all elements of tuple using cut/slice
operator ([:]) similar to lists.
=» Example:
t=(23,45,56.4,3+6j,’abc’)
print(t[:])#(23,45,56.4,3+6j,’abc’)
" Similar to the lists we can print tuple in a reverse
“ing cut/slice operator ([:])
Example:
«=(93,45,56.4,3+6j,'abc”
rint(t[: 1])#(23, 45,56.4,3+6j,’abc’)

COPYRIGHT OFFICE

LE VARIETIES

" It is possible to create a new tuple from another.
" Example:
= A=(1,34.5,’hello’,2+3})
= B=A # copies all elements of A to B, both points to same tuple.
= It is possible to create a tuple of tuple:
" Example:
" t1= (2, 5, 3)
" 12=(1,34,6)
" t3=(t1, t2)
- print{t3}#((2,5,3),(1,34,6))



vata structures in Python

RIETIES (CONT....)

" A tuple can be embedded in another tuple.
" Example:
= A=(1,2,3,4)
= B=(10,20,A,30)
= print(B) # (10,20,(1,2,3,4),30)
" Similar to lists, it is possible to concatenate two tuples.
= Example:
= A=(1,2,3,4)
" B=(10,20,30)
El C=A+B

ER à:
print(C}# (1,2,3,4,10,20,30)

vata structures in Python

= 1. t.count() : the count() method returns the number of
times a specified value appears in the tuple.
= Syntax:
t.count(value)# value is nothing but item to search
for in tuple t.
" Example:
t=(23,45,23,56.4,3+6j,’abc’)
print(t.count(23))#2
= 2. t.index() : Search for the first occurrence of the value 8
and return its position.
= Syntax:
t.index(value)# value is nothing but item to search
for in tuple t.
¿El Example:
92.15: 23,56.4,3+6j,’abc’)

vata structures in Python

ES: BUILT-IN FUNCTIONS

= 1. t.count() : the count() method returns the number of
times a specified value appears in the tuple.
= Syntax:
t.count(value)# value is nothing but item to search
for in tuple t.
" Example:
t=(23,45,23,56.4,3+6j,’abc’)
print(t.count(23))#2
= 2. t.index() : Search for the first occurrence of the value 8
and return its position.
= Syntax:
t.index(value)# value is nothing but item to search
for in tuple t.
¿El Example:
@ 3,45,23,56.4,3+6j,’abc’)
“print(t. index(23))#0

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF TUPLE

=" sum() : Calculates & Returns sum of all the elements of
tuple.

= Syntax: sum(t)

" Example:
" t=(1, 2, 3, 4, 5)
= print(sumft))

"= Note: Sum is calculated only for Numeric values, elsewise
throws TypeError.

" len() :Calculates & Returns total length of tuple.
" Syntax: len(tuple_name)
ıple:
t=(L, 2, 3 1, 2, 1, 2, 3, 2, 1)
eee
print(lénit))

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF TUPLE

"= min() : Calculates & Returns minimum of all the elements of
tuple.

=" Syntax: min(t)

" Example:
= t= (2.3, 4.445, 3, 5.33, 1.054, 2.5)
= print(min(t))

= max() :Calculates 8 Returns maximum of all the elements of
tuple.

=" Syntax: max(t)

ıple:
t=(1,2,3,1,2,1,2,3,2, 1)

ge:

‘ t)

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF TUPLE

= sorted() : returns a sorted list of the specified tuple.
" Syntax: sorted(tuple_name[, key[, Reverse_Flag ] |)
" Example:

" t= (2.3, 4.445, 3, 5.33, 1.054, 2.5]

= 11=sorted(t)

= Print(l1)

" 12=sorted(List, reverse=True)

" Print(l2)

Note: if Reverse_Flag = True then sorts in descending order
atherwise sort in ascending order, by default Reverse_Flag = False.

vata structures in Python

= This function returns true if all of the items are True (or if
the iterable is empty).

= All can be thought of as a sequence of AND operations on the
provided iterables.

" Syntax: all(list of iterables)
= Example:

= # print (all((True, True, True, True))) # Here all the iterables are

True so all will return True and the same will be printed

= print (all((False, True, True, False))) # False
El print (all((False, False, False))) # False

vata structures in Python

ANY() BUILT-IN FUNCTIONS

= Returns true if any of the items is True.

= It returns False if empty or all are false. Any can be thought
of as a sequence of OR operations on the provided iterables.

= Syntax: any(list of iterables)
" Example:
= # print (any((False, False, False, False))) # Here all the
iterables are False so any will return False and the same will

be printed

print (any((False, True, False, False))) # True
print, ny((True, False, False, False))) + True

er A A

vata structures in Python

" The zip() function returns a zip object, which is an
iterator of tuples where the first item in each passed
iterator is paired together, and then the second item in
each passed iterator are paired together and so on .....

" Syntax: zip(*iterables) # can be anything like lists,
tuples etc.

= If we do not pass any parameter, zip() returns an empty
iterator.

" Ifa single iterable is passed, zip() returns an iterator of
tuples with each tuple having only one element.

passed iterators have different lengths, the
the least items decides the length of the

vata structures in Python

ZIP() BUILT-IN FUNCTIONS

" Examplel:
a=zip()
b=list(a)
print(b)#[]

" Example2:
number_list = [1, 2, 3]
str_list = ['one', 'two', 'three']
Result=zip(number_list,str_list)

™ (Result)
El

vata structures in Python

ING THE ZIPPED LIST

= The * operator can be used in conjunction with zip() to
unzip the list. a=zip()

Example:

number_list = [1, 2, 3]

str_list = ['one', 'two', 'three']
Result=zip(number_list,str_list)
R=tuple(Result)

num, str=zip(*R)

print(num)
print(str)

vata structures in Python

PROBLEM STATEMENT: 01

" Create 3 lists - a list of names, a list of ages, a list
of salaries. Generate and print a list of tuples
containing name, age and salary from the 3 lists.
From this list generate 3 tuples — one containing
all names, another containing all ages and third
containing all salaries.

vata structures in Python

names_list=[‘abc’,’xyz’,’pqr’]
ages_list=[23,45,32]
salaries_list=[2300,8600,6700]
l=list(zip(names, ages, salaries)]

print(l)

name _tuple, age _tuple, salary_tuple=zip(*l)
print(name_tuple)

print(age_tuple)

print(salary_tuple)

vata structures in Python

(GSLEM STATEMENT: 02
" Create a list of tuples. Each tuple should contain
an item and its price in float. Write a program to
sort the tuples in descending order by price.

vata structures in Python

= divmod() function takes two argument and return
the tuple of quotient and the reminder.

= Examplel:
Result=divmod(17,3)
print(Result)

= Example2:
t=(17,3)
R=divmod(*t)

RACTICE QUESTIONS:

a) Write a program to obtain transpose of a 3x4
matrix using zip().

b) Write a program to multiply two matrices x(2x3)
and y(2x2) using list comprehension and zip
function.

c) Suppose we have a list of 5 integers and a tuple of
5 floats. Can we zip them and obtain an iterator.
If yes, how ?

d) Write a program to unzip a list of tuples into
individual lists

= "pose a date is represented as a tuple (d, m, y).
Lea program to create 2 date tuples and find
nutaber of days between the two dates.

vata structures in Python

COPYRIGHT OFFICE
N

„ASSIGNMENT NO: 03

Date 08)

Store the data about shares held by a user as tuples
containing the following information about shares.

Share name

Date of purchase

Cost price

Number of shares

Selling price

Write a program to determine:
a) Total cost of portfolio

BansE ll amount gained or lost.

¿ :entägé-profit made or loss incurred.

vata structures in Python

CE

SEE-IN PYTHON: INTRODUCTION

" A set is an unordered collection of items which are
separated by comma (,) and enclosed in curly
brackets ({}).

= Items of a set can be of any data type.
= set do not contain duplicate values
= Example:

A={20} # set with 1 value.

B={abc’,34,7+3j,90.45} # set with multiple items.
C={10,10,10,10} # only 1 10 gets stored.

vata structures in Python

THON: INTRODUCTION (CONT...)

" Set is an unordered collection; hence order of
insertion is not same as the order of access.
=" Example:
A={15,25,35,45,55}
print(A) # doesn’t always print {15,25,35,45,55}

= The elements in the set are immutable(cannot be
modified) but the set as a whole is mutable i.e. We
can add or remove items from it.

vata structures in Python

THON: INTRODUCTION (CONT....)

= A set() function can be used to convert a string, ,
list or tuple into a set.

= Example:
L=[10,20,30,40,50]
T=(‘abe’, 25, 32.435)
S=Programming'
S1=set(L) #{30, 20, 10, 40, 50}
S2=set(T) # fabc’, 32.435, 25}
S3=set(S) HP”, ’r’, ‘g’, O, ‘m’, n’,’g’}

“ll :: While creating set using set(), repetitions are

vata structures in Python

EMPTY SET

"= Empty set can be created by using a set()
constructor.
" Example:

S=4 # It will create empty dictionary
S=set() # It will create empty set

= Note: It is not possible to create empty set by
using { , instead it creates empty dictionary. To
create empty set, we must use set() constructor.

vata structures in Python

CESSING SET ELEMENTS:

eing an unordered collection, items in a set
cannot be accessed using indices.

" Sets can not be sliced using [|].

= Entire set can be printed by just using the name of
the set.

= Example:

S={10, 20, 30, 40, 50} #{30, 20, 10, 40, 50}

" Like strings, lists and tuples, sets can be iterated
over, using a for loop.

=" Example:

„m >={10, 20, 30, 40, 50}

print(i)

vata structures in Python

creating sets
Example:
S={10, 20, 30, 40, 50} #{30, 20, 10, 40, 50}
= We can use membership operator with set as
Example:
S=(10, 20, 30, 40, 50}
print(12 in S) # False
print(12 not in S) # True
= Set can be deleted by using del keyword
Example:
S={10, 20, 30, 40, 50}
del S

print(S) # NameError

le]

vata structures in Python

COFYRIG!

"EXAPERATIONS: (CONT...)
is possible to unpack a set within using *.

Example:
S={10, 20, 30, 40, 50} #{30, 20, 10, 40, 50}
S1={100,*S,200}
print(*S1)

= A set can not contain a set embedded in it.

" Sets can also be used to perform mathematical set
operations like union, intersection, symmetric
difference, etc.

vata structures in Python

N FUNCTIONS OF SET

=" sum() : Calculates & Returns sum of all the elements of set.
=" Syntax: sum(s)
" Example:

= s={1, 2, 3, 4, 5}

= print(sum(s))

= Note: Sum is calculated only for Numeric values, elsewise
throws TypeError.

" len() :Calculates & Returns number of items in a set.
= Syntax: len(s)

" Example:

E s= (1,2,3, 4,2, 1,2, 3,2, 1}

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF SET

"= min() : Calculates & Returns minimum of all the elements of
set.

= Syntax: min(s)
" Example:

" s= (2.3, 4.445, 3, 5.33, 1.054, 2.5}
= print(min(s))

" max() :Calculates & Returns maximum of all the elements of
set.

" Syntax: max(s)

= ıple:
s= 1,2 3, 1, 2, 1, 2, 3, 2, 1}
printfmax{s))

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

N FUNCTIONS OF SET

= sorted() : returns a sorted list of the specified set.
= Syntax: sorted(set_name/,key/, Reverse_Flag ] |)
" Example:

= s = (2.3, 4.445, 3, 5.33, 1.054, 2.5}

= 11=sorted(s)

" print(l1)

" 12=sorted(s, reverse=True)

= print(l2)

Note: if Reverse_Flag = True then sorts in descending order
atherwise sort in ascending order, by default Reverse_Flag = False.

vata structures in Python

COPYRIGHT
NEW DE
Reg. No.

L() BUILT-IN FUNCTIONS

= This function returns true if all of the items are True (or if
the iterable is empty).
= All can be thought of as a sequence of AND operations on the
provided iterables.
" Syntax: all(s)
= Example:
= # print (all({True, True, True, True})) # Here all the iterables

are True so all will return True and the same will be printed

= print (all({False, True, True, False})) # False

E] print (all({False, False, False})) # False

vata structures in Python

COPYRIGHT
NEW DE
Reg. No.

() BUILT-IN FUNCTIONS

= Returns true if any of the items is True.

= It returns False if empty or all are false. Any can be thought
of as a sequence of OR operations on the provided iterables.

= Syntax: any(s)
" Example:
= # print (any({False, False, False, False})) # Here all the
iterables are False so any will return False and the same will
be printed
= print (any({False, True, False, False})) # True
print (any({True, False, False, False})) # True

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

TIONS/METHODS

=" add(ele):

= If we want to add a single element to an existing set, we can
use the .add() operation.

= It adds the element to the set and returns 'None'.

= If the element already exists then add() method do not add
an element.

= Syntax: s.add(ele) # adds element ele to set s
= Example:
S={10, 20, 89, 09}
S.add(100)
print(S) # {10, 89, 09, 100, 20}
».add(10)
: {10, 89, 09, 100, 20}

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

TIONS/METHODS

=" update(seq):

= If we want to add a sequence of items then we use it.

= seq can ba list, tuple , set or dictionary(If seq is dictionary
then only keys will be added to set & not values).

= It adds the elements of seq to the set and returns 'None'.

"If the elements of seq already exists then .update() method
do not add the elements.

" Syntax: s.update(seq) # adds elements of seq to set s
= Example:
S={10, 20, 89, 09}
S.update([100,200])
rint(S) # (10, 89, 09, 100, 20}
update((12, 13))
rint(Sj'#{10, 89, 09, 100, 20,13,12}

vata structures in Python

TIONS/METHODS

= This method removes all elements of a set and return None.
= Syntax: s.clear() # removes all elements of set s
= Example:

S=(10, 20, 89, 09}

S.clear()

print(S) # set()

print(s.clear()) # None

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

TIONS/METHODS

= This method removes element ele from the set.
= If element does not exist, it raises a KeyError.
" The method returns None.
" Syntax: s.remove(ele) # removes element ele of set s
" Example:
S={10, 20, 89, 09}
S.remove(20)
print(S) # {10, 89, 09}
print(s.remove(10)) # None
print(s.remove(20)) # KeyError is raised

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

TIONS/METHODS

= discard(ele):
= This method also removes element ele from the set.

= If element does not exist, it does not raise a KeyError.
The method returns None.

= Syntax: s.discard(ele) # removes element ele of set s
= Example:

S={10, 20, 89, 09}

S.discard(20)

print(S) # {10, 89, 09}

print(s.discard(10)) # None

print(s.discard(20)) # KeyError not raised

vata structures in Python

COPYRIGHT OFFICE
NEW DELHI

TIONS/METHODS

= This operation removes and return an arbitrary element
from the set.

= If there are no elements to remove, it raises a KeyError.
= Syntax: s.pop() # removes arbitrary element of sets
= Example:
S={10, 20, 89, 09}
S.pop() # arbitrary element is popped and returned.
print(S) # arbitrary element which is popped
print(s.pop()) #
print(s.pop(20)) # KeyError raised

vata structures in Python

SETRFUNCTIONS/METHODS

= The copy() method returns a shallow copy of the set.
= Aset can be copied using = operator in Python.
= Example:
S=(2,35,79,0}
S1=S
print(S1)
S1.add(100)
print(S) + (85, 79, 0, 2, 100)
print(S1) # (35, 79, 0, 2, 100}
= Note: The problem with copying the set in this way is that if you modify the set S1,
the set S is also modified.
= Syntax: s.copy() # creates a shallow copy, changes made in shallow copy
do not change original set.

= Example:
S={10, 20, 89, 09}
1=S.copy() #
El rint(S) +

rint(Seopys)) #
rint(s.pop(20)) # KeyError raised

vata structures in Python

= This function returns length of the object.
= Syntax: object.__len__()
= Note: object can be a list, tuple, set or dictionary.
" Example:
S={2,35,79,0}
print(S._len__())

vata structures in Python

COPYRIGHT OFFICE

MAHEMATICAL OPERATIONS : UNION

Rel
Date 09/05/2024

" sl.union(s2) :

" This method returns union of set and set of
elements in an iterable object s2.
= Sometimes, the | operator is used in place
of union() method, but it operates only on the set of
elements in set.
"Syntax: sl.union(s2)# here s2 can be set, list,
tuple, dictionary
or
s1|s2 # here s2 must be set only.
" Example:
s1={0,1,2,6}
-9.325{34,54,6}
© print(s1.union(s2)) #{0,54,34,6,1,2,6}

vata structures in Python

AMPLES ON UNION
acker”)

" print(s.union(“Rank”))

" print(s.union([R”,'a”,'n”,'k”))
" print(s.union((‘R’,’a’,’n’,’*k)))
" print(s.union({“Rank”:1}))

= Note: when we use dictionary as an argument to
union it will add key only in a union set.

= print(s | “Rank”)

= print(s | [‘R’, ’a a es n ? , K] )
ES
(s|£Rank”:1)

(s| {R’, a, n° k”)

vata structures ın P

COPYRIGHT OFFICE

MA TFEMATICAL OPERATIONS : INTERSECTION

Rel
Date 09/05/2024

= sl.intersection(s2) :

= The intersection() method returns the intersection of a
set and the set of elements in an iterable object s2.
"Sometimes, the & operator is used in place of
the intersection() method, but it only operates on
the set of elements in set.
= Syntax: sl.intersection(s2)# here s2 can be set, list,
tuple, dictionary
or
s1&s2 # here s2 must be set only.
" Example:
s1={0,1,2,6}
> $2={34,54,6}
“ print(s1.intersection(s2)) +6)

vata structures in Python

„MORE EXAMPLES ON INTERSECTION
acker”)

" print(s.intersection(“Rank”))

" print(s.intersection([R”,'a”,'n”,'k”))

= Print(s.intersection((‘R’,’a’,’n’,’k’))

= Print(s.intersection({*Rank”:1}))

= Note: when we use dictionary as an argument to
union it will add key only in a union set.

" print(s8 Rank”)

" print(s&[‘R’, ‘a’, ’n’, 'k7] )
BE (s&(‘R’, ’a’, ’n’, *k’))
(s&fRank”: 1)
s&{R’, ’a’, ’n’,’ k))

vata structures in {si

COPYRIGHT OFFICE
Ney

HÉMATICAL OPERATIONS: INTERSECTION UPDATE

sl.intersection_update(s2) :

" This method update s1 with the intersection of
sl and s2 (iterable object) given in argument by
removing the items in s1 that are not present in
both sl and s2.

" This method returns None

"Syntax: sl.intersection_update(s2)

"Example:

>>S1={2,4,5,0}

>>S2={5,0,9,8}
>>print(sl.intersection_update(s2)) #None
>>s1. intersection_update(s2) #
>>817tt:(5,0)

vata structures in Python

" The difference() returns a set with all the elements
from the set that are in s1 but not in an iterable
s2.

" Sometimes the - operator is used in place of
the difference() , but it only operates on the set of
elements in set.

= Syntax: sl.difference(s2) there s2 can be set, list,
tuple, dictionary

or
s1-s2 # here s2 must be set only.
"Fvomple:
El „S1=1,4,5,0}
>82=15.0;9,8)
>print(s1.difference(s2)) # {2,4}

vata structures in Python

COPYRIGHT OFFICE
N

MÂTHÉMATICAL OPERATIONS: DIFFERENCE_UPDATE

s1.difference_update(s2) :

" This method update sl with the difference of sl
and s2 (iterable object) given in argument by
removing the items that exist in both sets.

" This method returns None

"Syntax: s1.difference_update(s2)

" Example:

>>S1={2,4,5,0}

>>S2=(5,0,9,8)
>>print(s1.intersection_update(s2)) #None
>>s1. difference_update(s2) #

El >>s1 4 2,4)



vata structures in Python

COPYRIGHT OFFICE

ATICAL OPERATIONS: SYMMETRIC_DIFFERENCE
etric_difference(s2) :
" Return a set that contains all items from both
sets, except items that are present in both sets:
= Sometimes the ‘ operator is used in place of
the symmetric_difference() , but it only operates on
the set of elements in set.
= Syntax: sl.symmetric_difference(s2) #here s2 can
be set, list, tuple, dictionary
or
s1/4s2 # here s2 must be set only.
" Example:
~>S1={2,4,5,0}
El >52=(5,0,9,8)
>pfäntf&Esymmetrci_difference(s2)) # (2,4,9,8)

vata structures in Python

GAL OPERATIONS : SYMMETRIC_DIFFERENCE_UPDATE

sl.symmetric_difference_update(s2) :

" This method update s1 with the
symmetric_difference()of sl and s2 ( iterable
object)

" This method returns None

" Syntax: sl.symmetric_difference_update(s2)

" Example:

>>S1={2,4,5,0}

>>S2={5,0,9,8}
>>print(sl.intersection_update(s2)) #None
>>s1. symmetric_difference_update(s2) #
42,4,9,8)

>>s lb;

vata structures in Python

COPYRIGHT OFFICE

[ICAL OPERATIONS: ISDISJOIN()
oint(s2) :

= Return True if no items in set sl is present in
set s2.

Reg
Date 0)

"Syntax: s1.isdisjoint(s2) #here s2 can be set, list,
tuple, dictionary

= Example:
>>s1={2,4,5,0}
>>s2={5,0,9,8}
>>print(s1.isdisjoint(s2)) # False
>>s2={3,7}
>> print(sl.isdisjoint(s2)) # True

vata structures in Python

COPYRIGHT OFFICE

TEMATICAL OPERATIONS: ISSUBSET()

= Return True if all items in set s1 are present in set s2.
= Sometimes the <= operator is used in place of
the issubset() , but it only operates on the set of
elements in set.
= Syntax: sl.issubset(s2) #here s2 can be set, list,
tuple, dictionary
Or
sl<=s2
" Example:
>>s1={2,4,5,0}
~>s2={5,0,9,8}
>print(s1.issubset(s2)) + False
>s222455,0,9,8)
> print(s1.issubset(s2)) # True

vata structures in Python

COPYRIGHT OFFICE

TEMATICAL OPERATIONS: ISSUPERSET()

= Return True if all items in set s2 are present in set s1.
= Sometimes the >= operator is used in place of
the issuperset() , but it only operates on the set of
elements in set.
= Syntax: sl.issuperset(s2) #here s2 can be set, list,
tuple, dictionary
Or
sl>=s2
" Example:
>>s1={2,4,5,0}
~>s2={5,0,9,8}
>print(s1.issuperset(s2)) # False
>s F455}

> print(s1.issuperset(s2)) # True

vata structures in Python

COPYRIGHT OFFICE

HENSION

comprehensions, set comprehensions offer
an easy way of creating sets. It consists of braces
containing an expression followed by a for clause,
and zero or more for or if clauses.

=" General form of set comprehension is:

"s={ expression for var in sequence [optional for
and/or if] }

" Example:
a={x**2 for x in range(5) }
print(a) #
= »={num for num in a if num > 2 and num < 10}

| orint(b
ES

vata structures in Python

RY IN PYTHON : INTRODUCTION

= Python dictionary is mutable and an unordered collection of
items where each item of a dictionary has a key/value pair.

=" Each key is separated from its value by a colon (:).

" The items are separated by commas, and the whole thing is
enclosed in curly braces.

"= An empty dictionary without any items is written with just
two curly braces, like this: ÿ.

=" Keys are unique within a dictionary while values may not
be.

" The values of a dictionary can be of any type, but the keys
must be of an immutable data type such as strings,
numbers, or tuples.

ralues can be of any data type and can repeat, but keys
be_of immutable type (string, number or tuple with
itable elements) and must be unique.

vata structures in Python

ON ARY IN PYTHON : INTRODUCTION (CONT..)

Dictionary keys are case sensitive, same name
but different cases of Key will be treated distinctly.

= Syntax: d=fkeyl:valuel, key2:value2,....}
= Example:
d=4 #empty dictionary
d1={1:’one’,4:’four’,9:’nine}
print(d1)

dict = (Name': Xyz', 'Age': 18, 'Class': Third'y;
print("dict['Name']: ", dict['Name'])

ll Dict = (Name': XYZ’, 1: [1, 2, 3, 4}
4 pritt(\nDictionary with the use of Mixed Keys: ")
print(Dict)

vata structures in Python

COPYRIGHT OFFICE

CFONARY : ACCESSING ELEMENTS
While indexing is used with other data types to access
values, a dictionary uses keys.

=" Keys can be used either inside square brackets [] or with
the get() method.

= If we use the square brackets [], KeyError is raised in case a
key is not found in the dictionary.

" On the other hand, the get() method returns None if the key
is not found.

" Example:

= # get Vs [] for retrieving elements
d={name': ‘XYZ’, 'age': 26}
print(d[‘name']) # XYZ
print(d.get('age')) + 26
print(d.get('address'))#None
priftiál'address' ])#KeyError

vata structures in Python

RY : ITERATING USING FOR LOOP
ary can be iterated over in following ways:
d=(name' : 'XYZ', 'age' : 25, 'salary' : 3445}
for k in d:
print(k) # prints all keys of the dictionary
= Iterate over key-value pairs:
for x in d.items():
print(x) # prints tuples of key-value pair
for k, v in d.items():
print(k, v) # prints key-value pairs
" Iterate over keys:
for k in d.keys():
print(k) # prints keys
te over values:
Sin d.values():
print(v) # prints values

for

vata structures in Python

QNARY : OPERATIONS

We can change the value of a specific item by
referring to it’s key name.

= Example:
d={name' : 'XYZ', 'age' : 25, 'salary' : 3445}
d['salary']=10000
print(d)
= We can also check if key exists using membership
operator.
= Example:
d={name' : 'XYZ', 'age' : 25, 'salary' : 3445}
if 'age' in d:
_ print(Yes, age is one of the key in
à dictionary’)

vata structures in Python

ON ARY : DELETING KEY FROM DICTIONARY

using del keyword we can remove the item
with the specified key name.

= Example:
d={name' : 'XYZ', 'age' : 25, 'salary' : 3445}
del d['salary
print(d)

= We can also delete the complete dictionary
using del keyword.
= Example:
d={name' : 'XYZ', 'age' : 25, 'salary' : 3445}
del d
2rint(d) # NameError: name 'd' is not defined

vata structures in Python

“TONE

'Y : BUILT-IN METHODS
, d=(1:'one', 4:‘four', 9:‘nine}

" sum() : calculate and return sum of all keys of d if
keys are numeric.

" Example: print(sum(d)) #14

" min() : returns minimum of all keys in d.

" Example: print(min(d)) + 1

=" max() : returns maximum of all keys in d.
" Example: print(max(d)) # 9

= len() : returns number of key - value pairs.
= Example : print(len(d)) # 3

‘d() : returns list by sorting the dictionary in
idifig-órder based on keys.

amendple : print(sorted(d)) + [1,4,9]

ARY : METHODS
d={8:‘eight', 4:‘four', 9:‘nine'}

>

Clear(): Removes all the elements from the dictionary. It returns
None

= Syntax: d.clear()

Example:
d.clear() # d is dictionary
print(d) #£
= Copy(): Returns a copy of the dictionary.
= Syntax: d.copy()
= Example:
= d1=d.copy()
= AI21=example’
d)#

vata structures in Python

RY : METHODS

=(8:“eight', 4:“four', 9:‘nine'}

fromkeys(): Returns a dictionary with the specified keys and a value.
" Syntax: dict.fromkeys(seq |, value])

Note:Value is optional, if not provided None will be added as
value.

" Example:
d=§
x={a’, Vv’, k}
d1=d.fromkeys(x) #
print(d1) + d1={‘a’:None, ‘v’: None,’k’:None}
y=10
d2=d.fromkeys(x, y)
“nt(d2) + di=fa”:10, ‘v’: 10, ’k’ :10}
1,2]
= - dfromkeys(x, z)

vsuprint(d3) # d1={a%[1, 2], v’ [1, 2], ’ :[1, 2}

SF 1ONARY : METHODS

" Consider, d={8:‘eight', 4:‘four', 9:‘nine'}

" get(): The get() method returns the value of the item
with the specified key.

" Syntax: d.get(key [,value])

" Note:Value is optional, A value to return if the
specified key does not exist. Default value None.

" Example:

x=d.get(8,’xyz))
print(x)
~=d.get(7,’abc’)

ONARY : METHODS
onsider, d={8:‘eight', 4:‘four', 9:‘nine'}

= items(): The items() method returns a view
object. The view object contains the key-value
pairs of the dictionary, as tuples in a list.

= The view object will reflect any changes done to
the dictionary, see example below.

= Syntax: d.items() #where d is dictionary.

= Example:

x=d.items()
aoe

Fins

COPYRIGHT OFFICE

ÆHCLIONARY : METHODS

. Consider, d={8:‘eight', 4:‘four', 9:‘nine'}

= keys(): The keys() method returns a view object.
The view object contains the keys of the
dictionary, as a list.

=" The view object will reflect any changes done to
the dictionary, see example below.

= Syntax: d.keys() #where d is dictionary.
" Example:

x=d.keys()

print(x)
1[1]='one”

TION, ARY : METHODS
ider, d={8:‘eight', 4:‘four', 9:‘nine'}

= pop(): The pop() method removes the specified item
from the dictionary.

= The value of the removed item is the return value
of the pop() method.

= Syntax: d.pop(key [,defaultValue]) #where d is
dictionary.

= Note: Optional. A value to return if the specified
key do not exist.

= Example:

orint(d.pop(8,’hello’))#eight

orint -pop(1,’hello’)) #hello

orint(d.pop(2))# KeyError

im Python

ARY : METHODS

Consider, d={8:‘eight', 4:‘four', 9:‘nine'}

popitem(): method removes the item that was last
inserted into the dictionary.

The removed item is the return value of
the popitem() method, as a tuple

Syntax: d.popitem() #where d is dictionary.

Example:

print(d.popitem())#

ARY : METHODS

=" Consider, d={8:‘eight', 4:‘four', 9:‘nine'}

= setdefault(): The setdefault() method returns the value of the
item with the specified key.

" If the key does not exist, insert the key, with the specified
value.

= Syntax: d.setdefault(key [,value]) #where d is dictionary.

= Note: Value is Optional.
If the key exist, this parameter has no effect.
If the key does not exist, this value becomes the key's value.
Default value None

" Example:

arint(d.setdefault(8,'hello”)tteight

arint(d, setdefault(1, ’hello’)#inserts 1:hello & return hello
>rint(d'Sétdefault(2)fNone

vata structures in Python

ARY : METHODS

=" Consider, d={8:‘eight', 4:‘four', 9:‘nine'}
=" update(): The update() method inserts the specified items to
the dictionary. It returns None.

" The specified items can be a dictionary, or an iterable object
with key value pairs.

= Syntax: d.update(iterable) #where d is dictionary.

= Example:

d.update([(2,’two’),(3,’three’)])

print(d)#

d.update(((4,'two”),(5,'three”))

print(d)

1.update({0:’zero’,6:’six’})

orintíd)s

ae

vata structures in Python

ARY : METHODS

=" Consider, d={8:‘eight', 4:‘four', 9:‘nine'}

= values(): The values() method returns a view object. The view
object contains the values of the dictionary, as a list.

= The view object will reflect any changes done to the dictionary.
" Syntax: d.values() #where d is dictionary.

" Example:
X=d.values()
print(X)
d[8]=‘example’ # Changes will be reflected in X also.
print(d)
orint(X) #

vata structures in Python

ARY : METHODS

= Consider, d={8:‘eight', 4:‘four', 9:‘nine'}
= _ len (): The __len__() method returns length of

dictionary.
= Syntax: d._len__() #where d is dictionary.
= Example:
X=d._ len_ ()

print(X)

DICTIONARY:

=" Dictionary within dictionary is called nested
dictionary is called nested dictionary.

= Example:
Employee={
'xyz': {dob':'23/12/2020','age':23},
'abc': {'dob':'13/04/2021','age':20},
‘pqr': {'dob':'21/02/2019','age':18}
}
print(Employee)

vata structures in Python

for i,j in Employee.items():
print(i,j)

for iin Employee.items():
print(i)

for i in Employee.keys():
print(i)

“or iin Employee.values():
El en
print(i)

vata structures in Python

Dictionary Comprehension

General form is:
d={key:value for (key,value) in d.items()}

= Example:
d=fa’:1,’b’:2,’c’:3,’d’:4,’e’:5}
#Obtain dictionary with each value cubed
d1={k:v**3 for (k,v) in d.items()}
print(d1)#dictionary with each value cubed
#obtain dictionary with each value cubed if value>3
d2={k:v for (k,v) in d.items() if v>3}
print(d2)
*"Jentify odd and even entries in the dictionary
aol ={k:((EVEN’ if v%2==0 else ‘ODD’ for (k,v) in
ters ke

Dal

102

tionary Comprehension

" Create two lists' students and marks. Create a
dictionary from these two lists using dictionary
comprehension. Use names as keys and marks as
values.

= Answer:

Istnames=[‘Sunil’,’Anuj’,’Rahul’,’Anuja’,’Rohit’]

Istmarks=[54,65,45,67,78]

E ={k:v for (k,v) in zip(lstnames,lstmarks)}

“intid): .

ere A

Data Structures in Python

oblem Statement: 01

« Write a program that reads a string from
the keyboard and creates dictionary
containing frequency of each character
occuring in the string.

- oblem Statement: 02

" A sparse matrix is a matrix most of
whose elements have a value 0. Suppose
we have a 5x5 sparse matrix stored as a
list of lists. Dictionary should store the
row and column of a non-zero element
as a tuple key and the value of the non-
zero element as the value against the
key tuple.

.—

oblem Statement: 03

" Given the following dictionary:

" Marks={‘subu’:{Math’:88,’Eng’:60,’Sst’:95},
‘Amol’:{Math’:78,’Eng’:68,’Sst’:89},
‘Rama’:{Math’:68,’Eng’:66,’Sst’:87},
‘Raka’:{Math’:88,’Eng’:68,’Sst’:95}}

Write a program to perform the following

operations:

a) Print marks obtained by amol in English

b) Set marks obtained by Rama in Maths to

the-dictionary by name

106

" Create a dictionary which stores following data:

Interface IP Address status
EthoO 1.1.1.1 up
Eth1 2.2.2.2 up
WlanO 3.3.3.3 down
Wlani 4.4.4.4 up

" Write a program to perform following
operations:

a) Find the status of a given interface
b) Find Interface and IP of all interfaces which

ara ™)p.

sud ae total number of interfaces

References:

" Let us Python by Yashwant Kanetkar

Python Programming by Rao, K. Nageswara
Shaikh Akbar

Introduction to Programming with Python

by Techknowledge publications.

=" www.w3schools.com

a “-geeksforgeeks.org