Python 2024 Lecture Final
Python 2024 Lecture Final
DATA STRUCTURES:
Data Structures in Python provides / include Python list, Python Tuple, Python set, and
Python dictionaries with their syntax and examples.
Here in this data structure we will come to know as a way of organizing and storing
data such that we can access and modify it efficiently
List:
>>> x=list()
>>> x
[]
>>> tuple1=(1,2,3,4)
>>> x=list(tuple1)
>>> x
[1, 2, 3, 4]
The list data type has some more methods. Here are all of the methods of list objects:
List Operations:
Del()
Append()
Extend()
Insert()
Pop()
Remove()
Reverse()
Sort()
Delete: Delete a list or an item from a list
>>> x=[5,3,8,6]
>>> del(x[1]) #deletes the index position 1 in a list
>>> x
[5, 8, 6]
>>> del(x)
>>> x # complete list gets deleted
Append: Append an item to a list
>>> x=[1,5,8,4]
>>> x.append(10)
>>> x
[1, 5, 8, 4, 10]
Extend: Append a sequence to a list.
>>> x=[1,2,3,4]
>>> y=[3,6,9,1]
>>> x.extend(y)
>>> x
[1, 2, 3, 4, 3, 6, 9, 1]
Insert: To add an item at the specified index, use the insert () method:
>>> x=[1,2,4,6,7]
>>> x.insert(2,10) #insert(index no, item to be inserted)
>>> x
[1, 2, 10, 4, 6, 7]
>>> x.insert(4,['a',11])
>>> x
Pop: The pop() method removes the specified index, (or the last item if index is not
specified) or simply pops the last item of list and returns the item.
>>> x.pop()
>>> x
[1, 2, 10, 4, 6]
>>> x.pop(2)
10
>>> x
[1, 2, 4, 6]
Remove: The remove() method removes the specified item from a given list.
>>> x=[1,33,2,10,4,6]
>>> x.remove(33)
>>> x
[1, 2, 10, 4, 6]
>>> x.remove(4)
>>> x
[1, 2, 10, 6]
>>> x.sort()
>>> x
[1, 2, 3, 4, 5, 6, 7]
>>> x=[10,1,5,3,8,7]
>>> x.sort()
>>> x
[1, 3, 5, 7, 8, 10]
Slicing: Slice out substrings, sub lists, sub Tuples using index.
Example:
>>> x=(1,2,3)
>>> print(x)
(1, 2, 3)
>>> x
(1, 2, 3)
-
>>> x=()
>>> x
()
-
>>> x=[4,5,66,9]
>>> y=tuple(x)
>>> y
(4, 5, 66, 9)
>>> x=1,2,3,4
>>> x
(1, 2, 3, 4)
Access tuple items: Access tuple items by referring to the index number, inside square
brackets
>>> x=('a','b','c','g')
>>> print(x[2])
c
Change tuple items: Once a tuple is created, you cannot change its values. Tuples are
unchangeable.
>>> x=(2,5,7,'4',8)
>>> x[1]=10
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
x[1]=10
TypeError: 'tuple' object does not support item assignment
>>> x
(2, 5, 7, '4', 8) # the value is still the same
Loop through a tuple: We can loop the values of tuple using for loop
>>> x=4,5,6,7,2,'aa'
>>> for i in x:
print(i)
4
5
6
7
2
aa
Count (): Returns the number of times a specified value occurs in a tuple
>>> x=(1,2,3,4,5,6,2,10,2,11,12,2)
>>>
x.count(2) 4
Index (): Searches the tuple for a specified value and returns the position of where it
was found
>>> x=(1,2,3,4,5,6,2,10,2,11,12,2)
>>>
x.index(2) 1
(Or)
>>> x=(1,2,3,4,5,6,2,10,2,11,12,2)
>>> y=x.index(2)
>>> print(y)
1
Length (): To know the number of items or values present in a tuple, we use len().
>>> x=(1,2,3,4,5,6,2,10,2,11,12,2)
>>> y=len(x)
>>> print(y)
12
Set:
A set is a collection which is unordered and unindexed with no duplicate elements. In
Python sets are written with curly brackets.
Example:
>>> x={1,3,5,6}
>>> x
{1, 3, 5, 6}
>>> x=set()
>>> x
set()
-
>>> list1=[4,6,"dd",7]
>>> x=set(list1)
>>> x
{4, 'dd', 6, 7}
Add (): To add one item to a set use the add () method. To add more than one item to a
set use the update () method.
>>> x={"svcet","college","cie","dept"}
>>> x.add("autonomous")
>>> x
{'svcet', 'dept', 'autonomous', 'cie', 'college'}
-
>>> x={1,2,3}
>>> x.update("a","b")
>>> x
{1, 2, 3, 'a', 'b'}
-
>>> x={1,2,3}
>>> x.update([4,5],[6,7,8])
>>> x
{1, 2, 3, 4, 5, 6, 7, 8}
Remove (): To remove an item from the set we use remove or discard methods.
>>> x={1, 2, 3, 'a', 'b'}
>>> x.remove(3)
>>> x
{1, 2, 'a', 'b'}
Len (): To know the number of items present in a set, we use len().
>>> z={'svcet', 'dept', 'autonomous', 'cie', 'college'}
>>> len(z)
5
Item in X: you can loop through the set items using a for loop.
>>> x={'a','b','c','d'}
>>> for item in x:
print(item)
c
d
a
b
pop ():This method is used to remove an item, but this method will remove the last item.
Remember that sets are unordered, so you will not know what item that gets removed.
>>> x={1, 2, 3, 4, 5, 6, 7, 8}
>>> x.pop()
1
>>> x
{2, 3, 4, 5, 6, 7, 8}
>>> x={1,2,3,4}
>>> y={4,5,6,7}
>>> print(x|y)
{1, 2, 3, 4, 5, 6, 7}
>>> x={1,2,3,4}
>>> y={4,5,6,7}
>>> print(x&y)
{4}
-
>>> A={1,2,3,4,5}
>>> B={4,5,6,7,8}
>>> print(A-B)
{1, 2, 3}
>>> B={4,5,6,7,8}
>>> A={1,2,3,4,5}
>>> print(B^A)
{1, 2, 3, 6, 7, 8}
Dictionaries:
A dictionary is a collection which is unordered, changeable and indexed. In Python
dictionaries are written with curly brackets, and they have keys and values.
Key-value pairs
Unordered
We can construct or create dictionary like:
X={1:’A’,2:’B’,3:’c’}
X=dict([(‘a’,3)
(‘b’,4)]
X=dict(‘A’=1,’B’ =2)
Examples:
>>> dict1 = {"brand":"svcet","model":"college","year":1959}
>>> dict1
{'brand': 'svcet', 'model': 'college', 'year': 1959}
svcet
college
1959
brand
mode
l year
>>> for i in
dict1.items():
print(i)
('brand', 'svcet')
('model', 'college')
('year', 1959)
Add/change values: You can change the value of a specific item by referring to its key
name
>>>{1: 1, 2: 4, 3: 9, 4: 16}
{1: 1, 2: 4, 3: 9, 4: 16}
>>> y=len(x)
>>> y
4
Iterating over (key, value) pairs:
>>> x = {1:1, 2:4, 3:9, 4:16, 5:25}
>>> for key in x:
print(key, x[key])
11
24
39
4 16
5 25
>>> for k,v in
x.items():
print(k,v)
11
24
39
4 16
5 25
List of Dictionaries:
1 John
2 Smith
3 Andersson
## Modify an entry, This will change the name of customer 2 from Smith to Charlie
>>> customers[2]["name"]="charlie"
>>> print(customers)
[{'uid': 1, 'name': 'John'}, {'uid': 2, 'name': 'Smith'}, {'uid': 3, 'name':
>>> print(customers)
[{'uid': 1, 'name': 'John', 'password': '123456'}, {'uid': 2, 'name': 'Smith', 'password':
'123456'}, {'uid': 3, 'name': 'charlie', 'password': '123456'}]
## Delete a field
>>> del customers[1]
>>> print(customers)
[{'uid': 1, 'name': 'John', 'password': '123456'}, {'uid': 3, 'name': 'charlie', 'password':
'123456'}]
>>> for x in
customers: del
x["uid"]
>>> x
{'name': 'John', 'password': '123456'}
Sequences:
A sequence is a succession of values bound together by a container that reflects their
type. Almost every stream that you put in python is a sequence. Some of them are:
String
List
Tuples
Range object
String: A string is a group of characters. Since Python has no provision for arrays, we
simply use strings. This is how we declare a string. We can use a pair of single or double
quotes. Every string object is of the type ‘str’.
>>> type("name")
<class 'str'>
>>> name=str()
>>> name
''
>>> a=str('svcet')
>>> a
'svcet'
>>> a=str(svcet)
>>> a[2]
'c'
List: A list is an ordered group of items. To declare it, we use square brackets.
>>> college=["cie","it","eee","ece","mech","aero"]
>>>
college[1] 'it'
>>>
college[:2]
['cie', 'it']
>>>
college[:3]
['cie', 'it', 'eee']
>>> college[3:]
['ece', 'mech',
'aero']
>>> college[0]="ciedept"
>>> college
['ciedept', 'it', 'eee', 'ece', 'mech', 'aero']
>>> hello=tuple(["svcet","college"])
>>> hello
('svcet', 'college')
Range object: A range() object lends us a range to iterate on; it gives us a list of
numbers.
>>> a=range(4)
>>> type(a)
<class 'range'>
>>> for i in
range(1,6,2):
print(i)
1
3
5
1. Indexing
Access any item in the sequence using its index.
String List
>>> x='svcet' >>> x=['a','b','c']
>>> print(x[2]) >>> print(x[1])
c b
2. Slicing
Slice out substrings, sub lists, sub tuples using index
[start : stop : step size]
>>> x='computer'
>>> x[1:4]
'omp'
>>> x[1:6:2]
'opt'
>>> x[3:]
'puter'
>>> x[:5]
'compu'
>>> x[-1]
'r'
>>> x[-3:]
'ter'
>>> x[:-2]
'comput'
>>> x[::-2]
'rtpo'
>>> x[::-1]
'retupmoc'
3. Adding/concatenation:
Combine 2 sequences of same type using +.
string List
>>> x='svcet' + 'college' >>> x=['a','b'] + ['c']
>>> print(x) >>> print(x)
Svcetcollege ['a', 'b', 'c']
4. Multiplying:
Multiply a sequence using *.
String List
>>> x='svcet'*3 >>> x=[3,4]*2
>>> x >>> x
'svcetsvcetsvcet' [3, 4, 3, 4]
5. Checking Membership:
Test whether an item is in or not in a sequence.
String List
>>> x='svcet' >>> x=['a','b','c']
>>> print('c' in x) >>> print('a' not in x)
True False
6. Iterating:
Iterate through the items in asequence
>>> x=[1,2,3]
>>> for item in x:
print(item*2)
2
4
6
If we want to display the items of a given list with index then we have to use
“enumerate” keyword.
>>> x=[5,6,7]
>>> for item,index in
enumerate(x):
print(item,index)
05
16
27
7. len():
It will count the number of items in a given sequence.
string List
>>> x="svcet" >>> x=["aa","b",'c','cc']
>>> print(len(x)) >>> print(len(x))
5 4
8. min():
Finds the minimum item in a given sequence lexicographically.
string List
>>> x="svcet" >>> x=["apple","ant1","ant"]
>>> print(min(x)) >>> print(min(x))
C ant
>>> x=["apple","ant1","ant",11]
>>> print(min(x))
9. max():
Finds the maximum item in a given sequence
string List
>>> x='cognizant' >>> x=["hello","yummy","zebra"]
>>> print(max(x)) >>>
Z print(max(x))
zebra
>>> x=["hello","yummy1","zebra1",22]
>>> print(max(x))
10. Sum:
Finds the sum of items in a sequence
>>> x=[1,2,3,4,5]
>>>
print(sum(x)) 15
>>> print(sum(x[-
2:])) 9
11.Sorted():
Returns a new list of items in sorted order but does not change the original list.
string List
>>> x='college' >>> x=['a','r','g','c','j','z']
>>> print(sorted(x)) >>> print(sorted(x))
['c', 'e', 'e', 'g', 'l', 'l', 'o'] ['a', 'c', 'g', 'j', 'r', 'z']
12.Count():
It returns the count of an item
string List
>>> x='college' >>> x=['a','b','a','a','c','a']
>>> print(x.count('l')) >>> print(x.count('a'))
2 4
>>> 'college'.count('l')
2
13.Index()
Returns the index of first occurrence
string List
>>> x='college' >>> x=['a','b','a','a','c','a']
>>> >>> print(x.index('a'))
print(x.index('l')) 2 0
Comprehensions:
List:
List comprehensions provide a concise way to create lists. Common applications are to make
new lists where each element is the result of some operations applied to each member of
another sequence or iterable, or to create a subsequence of those elements that satisfy a
certain condition.
>>> list1=[]
list1.append(x**2)
>>> list1
(or)
>>> list1
(or)
Which is more concise and redable.
>>> list1
>>> a=5
>>> table = [[a, b, a * b] for b in range(1, 11)]
>>> for i in table:
print(i)
[5, 1, 5]
[5, 2, 10]
[5, 3, 15]
[5, 4, 20]
[5, 5, 25]
[5, 6, 30]
[5, 7, 35]
[5, 8, 40]
[5, 9, 45]
[5, 10, 50]
Tuple:
Tuple Comprehensions are special: The result of a tuple comprehension is special. You
might expect it to produce a tuple, but what it does is produce a special "generator"
object that we can iterate over.
For example:
>>> x = (i for i in 'abc') #tuple comprehension
>>> x
<generator object <genexpr> at 0x033EEC30>
>>> print(x)
<generator object <genexpr> at 0x033EEC30>
You might expect this to print as ('a', 'b', 'c') but it prints as <generator object <genexpr>
at 0x02AAD710> The result of a tuple comprehension is not a tuple: it is actually a
generator. The only thing that you need to know now about a generator now is that you
can iterate over it, but ONLY ONCE. So, given the code
a
b
c
Create a list of 2-tuples like (number, square):
>>> z=[(x, x**2) for x in range(6)]
>>> z
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
Set:
Similarly to list comprehensions, set comprehensions are also supported:
Dictionary:
Dictionary comprehensions can be used to create dictionaries from arbitrary key and
value expressions:
Bubble Sort:
It is a simple sorting algorithm which sorts ‘n’ number of elements in the list by
comparing the ach pair of adjacent items and swaps them if they are in wrong order.
Algorithm:
1. Starting with the first element (index=0), compare the current element with the
next element of a list.
2. If the current element is greater (>) than the next element of the list then swap them.
3. If the current element is less (<) than the next element of the list move to the next
element.
4. Repeat step 1 until it correct order is framed.
For ex: list1= [10, 15, 4, 23, 0] so here we are comparing values again
Output:
unsorted list1 is [9, 16, 6, 26, 0]
[9, 16, 6, 26, 0]
[9, 6, 16, 26, 0]
[9, 6, 16, 26, 0]
[9, 6, 16, 0, 26]
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-
32/pyyy/bubb2.py unsorted list1 is [9, 16, 6, 26, 0]
[9, 16, 6, 26, 0]
[9, 6, 16, 26, 0]
[9, 6, 16, 26, 0]
[9, 6, 16, 0, 26]
# In a different way:
list1=[9,16,6,26,0]
print("unsorted list1 is", list1)
for j in range(len(list1)-1):
for i in range(len(list1)-1-j):
if list1[i]>list1[i+1]:
list1[i],list1[i+1]=list1[i+1],list1[i]
print(list1)
else:
print(list1)
print( )
print("sorted list is",list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/bubb3.py
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/bubb4.py
list1=[9,16,6,26,0]
print("unsorted list1 is",
list1) for j in
range(len(list1)-1):
for i in range(len(list1)-
1): if list1[i]<list1[i+1]:
list1[i],list1[i+1]=list1[i+1],list1[i]
print(list1)
else:
print(list1)
print( )
print("sorted list is",list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-
2/pyyy/bubbdesc.py unsorted list1 is [9, 16, 6, 26, 0]
[16, 9, 6, 26, 0]
[16, 9, 6, 26, 0]
[16, 9, 26, 6, 0]
[16, 9, 26, 6, 0]
[16, 9, 26, 6, 0]
[16, 26, 9, 6, 0]
[16, 26, 9, 6, 0]
[16, 26, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
[26, 16, 9, 6, 0]
Selection Sort:
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/selectasce.py
[5, 3, 7, 1, 9, 6]
[1, 3, 7, 5, 9, 6]
[1, 3, 7, 5, 9, 6]
[1, 3, 5, 7, 9, 6]
[1, 3, 5, 6, 9, 7]
[1, 3, 5, 6, 7, 9]
[1, 3, 5, 6, 7, 9]
#Write a python program to arrange the elements in descending order using selection
sort:
list1=[5,3,7,1,9,6]
print(list1)
for i in range(len(list1)):
min_val=max(list1[i:])
min_ind=list1.index(min_val)
list1[i],list1[min_ind]=list1[min_ind],list1[i]
print(list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/selecdecs.py
[5, 3, 7, 1, 9, 6]
[9, 7, 6, 5, 3, 1]
Note: If we want the elements to be sorted in descending order use max () method in place
of min ().
Insertion Sort:
Insertion sort is not a fast sorting algorithm. It is useful only for small datasets.
It is a simple sorting algorithm that builds the final sorted list one item at a time.
Algorithm:
# Write a python program to arrange the elements in ascending order using insertion
sort (with functions)
def insertionsort(my_list):
current_element=my_list[index]
pos=index
while current_element<my_list[pos-1]and
pos>0: my_list[pos]=my_list[pos-1]
pos=pos-1
my_list[pos]=current_element
list1=[3,5,1,0,10,2] num=int(input(“enter how many elements to be in
list”)) insertionsort(list1) list1=[int(input()) for i in range (num)]
print(list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-
32/pyyy/inserti.py [0, 1, 2, 3, 5, 10]
# Write a python program to arrange the elements in descending order using insertion
sort (with functions)
def insertionsort(my_list):
current_element=my_list[index]
pos=index
while current_element>my_list[pos-1]and
pos>0: my_list[pos]=my_list[pos-1]
pos=pos-1
my_list[pos]=current_element
#list1=[3,5,1,0,10,2]
#insertionsort(list1)
#print(list1)
insertionsort(list1)
print(list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/insertdesc.py
enter how many elements to be in list 5
8
1
4
10
2
[10, 8, 4, 2, 1]
Merge Sort:
Generally this merge sort works on the basis of divide and conquer algorithm. The three
steps need to be followed is divide, conquer and combine. We will be dividing the unsorted
list into sub list until the single element in a list is found.
Algorithm:
# Write a python program to arrange the elements in ascending order using Merge
sort (with functions)
def
mergesort(list1):
if len(list1)>1:
mid=len(list1)//2
left_list=list1[:mid]
right_list=list1[mid:]
mergesort(left_list)
mergesort(right_list)
i=0
j=0
k=0
while i<len(left_list) and j<len(right_list):
if left_list[i]<right_list[j]:
list1[k]=left_list[i]
i=i+1
k=k+1
else:
list1[k]=right_list[j]
j=j+1
k=k+1
while
i<len(left_list):
list1[k]=left_list[i
] i=i+1
k=k+1
while
j<len(right_list):
list1[k]=right_list[j
] j=j+1
k=k+1
num=int(input("how many numbers in
list1")) list1=[int(input()) for x in
range(num)] mergesort(list1)
print("sorted list1",list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/merg.py
how many numbers in
list15 5
9
10
1
66
sorted list1 [1, 5, 9, 10, 66]
Quick Sort:
Algorithm:
1. Select the pivot element
2. Find out the correct position of pivot element in the list by rearranging it.
3. Divide the list based on pivot element
4. Sort the sub list recursively
Note: Pivot element can be first, last, random elements or median of three values.
In the following program we are going to write 3 functions. The first function is to find pivot
element and its correct position. In second function we divide the list based on pivot element
and sort the sub list and third function (main fun) is to print input and output.
# Write a python program to arrange the elements in ascending order using Quick sort
(with functions)
#To get the correct position of pivot element:
def
pivot_place(list1,first,last):
pivot=list1[first]
left=first+1
right=last
while True:
while left<=right and list1[left]<=pivot:
left=left+1
while left<=right and
list1[right]>=pivot: right=right-1
if right<left:
break
else:
list1[left],list1[right]=list1[right],list1[left]
list1[first],list1[right]=list1[right],list1[first]
return right
#second function
def
quicksort(list1,first,last):
if first<last:
p=pivot_place(list1,first,last)
quicksort(list1,first,p-1)
quicksort(list1,p+1,last)
#main fun
list1=[56,25,93,15,31,44]
n=len(list1)
quicksort(list1,0,n-1)
print(list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-32/pyyy/qucksort.py
[15, 25, 31, 44, 56, 93]
# Write a python program to arrange the elements in descending order using Quick
sort (with functions)
#To get the correct position of pivot element:
def pivot_place(list1,first,last):
pivot=list1[first]
left=first+1
right=last
while
True:
while left<=right and list1[left]>=pivot:
left=left+1
while left<=right and
list1[right]<=pivot: right=right-1
if right<left:
break
else:
list1[left],list1[right]=list1[right],list1[left]
list1[first],list1[right]=list1[right],list1[first]
return right
def
quicksort(list1,first,last):
if first<last:
p=pivot_place(list1,first,last)
quicksort(list1,first,p-1)
quicksort(list1,p+1,last)
#main fun
list1=[56,25,93,15,31,44]
n=len(list1)
quicksort(list1,0,n-1)
print(list1)
Output:
C:/Users/SVCET/AppData/Local/Programs/Python/Python38-
Linked Lists:
Linked lists are one of the most commonly used data structures in any programming
language. Linked Lists, on the other hand, are different. Linked lists, do not store data at
contiguous memory locations. For each item in the memory location, linked list stores value
of the item and the reference or pointer to the next item. One pair of the linked list item and
the reference to next item constitutes a node.
The following are different types of linked lists.
class LinkedList:
def init (self):
self.head = None
self.last_node =
None
def display(self):
current = self.head
while current is not None:
print(current.data, end = ' ')
current = current.next
a_llist = LinkedList()
n = int(input('How many elements would you like to add? '))
for i in range(n):
data = int(input('Enter data item: '))
a_llist.append(data)
print('The linked list: ', end = '')
a_llist.display()
Program Explanation
Stacks:
Stack works on the principle of “Last-in, first-out”. Also, the inbuilt functions in Python
make the code short and simple. To add an item to the top of the list, i.e., to push an item,
we use append() function and to pop out an element we use pop() function.
# Python code to demonstrate Implementing stack using list
Output:
['Amar', 'Akbar', 'Anthony', 'Ram', 'Iqbal']
Iqbal
['Amar', 'Akbar', 'Anthony', 'Ram']
Ram
['Amar', 'Akbar', 'Anthony']
Queues:
Queue works on the principle of “First-in, first-out”. Time plays an important factor here.
We saw that during the implementation of stack we used append() and pop() function which
was efficient and fast because we inserted and popped elements from the end of the list, but
in queue when insertion and pops are made from the beginning of the list, it is slow. This
occurs due to the properties of list, which is fast at the end operations but slow at the
beginning operations, as all other elements have to be shifted one by one. So, we prefer the
use of collections. Deque over list, which was specially designed to have fast appends and
pops from both the front and back end.
Output:
deque(['Ram', 'Tarun', 'Asif', 'John'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar', 'Birbal'])
Ram
Tarun
deque(['Asif', 'John', 'Akbar', 'Birbal'])