Embed presentation


![ListIntroductionUsed for storing different types of data unlike arraysExample-1 student = [10, "Amar", 'M', 50, 55, 57, 67, 47]Example-2 e_list = [] #Empty ListIndexing + Slicing can be applied on listExample-1 print(student[1]) Gives "Amar"Example-2 print(student[0: 3: 1])Prints [10, "Amar", 'M']Example-3 student[::] Print all elements](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-3-2048.jpg&f=jpg&w=240)
![ListExamplesExample-1 #Create list with integer numbersnum = [10, 20, 30, 40, 50]print(num)print("num[0]: %dtnum[2]: %dn" % (num[0], num[2]))Example-2 #Create list with stringsnames = ["Ram", "Amar", "Thomas"]print(names)print("names[0]: %stnames[2]: %sn" % (names[0], names[2]))Example-3 #Create list with different dtypesx = [10, 20, 1.5, 6.7, "Ram", 'M']print(x)print("x[0]: %dtx[2]: %ftx[4]: %stx[5]: %cn" %(x[0], x[2], x[4], x[5]))](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-4-2048.jpg&f=jpg&w=240)

![ListUpdating list1 Creation lst = list(range(1, 5))print(lst)[1, 2, 3, 4]2 append lst.append(9)print(lst)[1, 2, 3, 4, 9]3 Update-1 lst[1] = 8print(lst)[1, 8, 3, 4, 9]4 Update-2 lst[1: 3] = 10, 11print(lst)[1, 10, 11, 4, 9]5 delete del lst[1]print(lst)[1, 11, 4, 9]6 remove lst.remove(11)print(lst)[1, 4, 9]7 reverse lst.reverse()print(lst)[9, 4, 1]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-6-2048.jpg&f=jpg&w=240)
![ListConcatenation of Two List'+' operator is used to join two listExample x = [10, 20, 30]y = [5, 6, 7]print(x + y)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-7-2048.jpg&f=jpg&w=240)
![ListRepetition of List'*' is used to repeat the list 'n' timesExample x = [10, 20, 30]print(x * 2)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-8-2048.jpg&f=jpg&w=240)
![ListMembership of List'in' and 'not in' operators are used to check, whether an element belongs to the listor notExample x = [1, 2, 3, 4, 5]a = 3print(a in x)Returns True, if the item is foundin the listExample x = [1, 2, 3, 4, 5]a = 7print(a not in x)Returns True, if the item is notfound in the list](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-9-2048.jpg&f=jpg&w=240)
![ListAliasing And Cloning ListsAliasing: Giving new name for the existing listExample x = [10, 20, 30, 40]y = xNote: No separate memory will be allocated for yCloning / Copy: Making a copyExample x = [10, 20, 30, 40]y = x[:] <=> y = x.copy()x[1] = 99print(x)print(y)Note: Changes made in one list will not reflect other](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-10-2048.jpg&f=jpg&w=240)

![ListTo find the common items#To find the common item in two listsl1 = ["Thomas", "Richard", "Purdie", "Chris"]l2 = ["Ram", "Amar", "Anthony", "Richard"]#Covert them into setss1 = set(l1)s2 = set(l2)#Filter intersection of two setss3 = s1.intersection(s2)#Convert back into the listcommon = list(s3)print(common)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-12-2048.jpg&f=jpg&w=240)
![ListNested List#To create a list with another list as elementlist = [10, 20, 30, [80, 90]]print(list)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-13-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-1: Create a list with squares of integers from 1 to 10#Version-1squares = []for x in range(1, 11):squares.append(x ** 2)print(squares)#Version-2squares = []squares = [x ** 2 for x in range(1, 11)]print(squares)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-14-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-2: Get squares of integers from 1 to 10 and take only the even numbers from theresulteven_squares = [x ** 2 for x in range(1, 11) if x % 2 == 0]print(even_squares)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-15-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-3: #Adding the elements of two list one by one#Example-1x = [10, 20, 30]y = [1, 2, 3, 4]lst = []#Version-1for i in x:for j in y:lst.append(i + j)#Version-2lst = [i + j for i in x for j in y]#Example-2lst = [i + j for i in "ABC" for j in "DE"]print(lst)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-16-2048.jpg&f=jpg&w=240)


![TupleCreating TuplesTo create empty tupletup1 = ()Tuple with one itemtup1 = (10, )Tuple with different dtypestup3 = (10, 20, 1.1, 2.3, "Ram", 'M')Tuple with no bracest4 = 10, 20, 30, 40Create tuple from the listlist = [10, 1.2, "Ram", 'M']t5 = tuple(list)Create tuple from ranget6 = tuple(range(4, 10, 2))](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-19-2048.jpg&f=jpg&w=240)






The document provides an in-depth discussion on lists and tuples in Python, covering their creation, indexing, updating, and various operations such as concatenation and membership testing. It also introduces list comprehensions and basic tuple operations, including immutability and tuple functions. Additionally, the document includes exercises for practical applications to reinforce understanding of these data structures.


![ListIntroductionUsed for storing different types of data unlike arraysExample-1 student = [10, "Amar", 'M', 50, 55, 57, 67, 47]Example-2 e_list = [] #Empty ListIndexing + Slicing can be applied on listExample-1 print(student[1]) Gives "Amar"Example-2 print(student[0: 3: 1])Prints [10, "Amar", 'M']Example-3 student[::] Print all elements](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-3-2048.jpg&f=jpg&w=240)
![ListExamplesExample-1 #Create list with integer numbersnum = [10, 20, 30, 40, 50]print(num)print("num[0]: %dtnum[2]: %dn" % (num[0], num[2]))Example-2 #Create list with stringsnames = ["Ram", "Amar", "Thomas"]print(names)print("names[0]: %stnames[2]: %sn" % (names[0], names[2]))Example-3 #Create list with different dtypesx = [10, 20, 1.5, 6.7, "Ram", 'M']print(x)print("x[0]: %dtx[2]: %ftx[4]: %stx[5]: %cn" %(x[0], x[2], x[4], x[5]))](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-4-2048.jpg&f=jpg&w=240)

![ListUpdating list1 Creation lst = list(range(1, 5))print(lst)[1, 2, 3, 4]2 append lst.append(9)print(lst)[1, 2, 3, 4, 9]3 Update-1 lst[1] = 8print(lst)[1, 8, 3, 4, 9]4 Update-2 lst[1: 3] = 10, 11print(lst)[1, 10, 11, 4, 9]5 delete del lst[1]print(lst)[1, 11, 4, 9]6 remove lst.remove(11)print(lst)[1, 4, 9]7 reverse lst.reverse()print(lst)[9, 4, 1]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-6-2048.jpg&f=jpg&w=240)
![ListConcatenation of Two List'+' operator is used to join two listExample x = [10, 20, 30]y = [5, 6, 7]print(x + y)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-7-2048.jpg&f=jpg&w=240)
![ListRepetition of List'*' is used to repeat the list 'n' timesExample x = [10, 20, 30]print(x * 2)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-8-2048.jpg&f=jpg&w=240)
![ListMembership of List'in' and 'not in' operators are used to check, whether an element belongs to the listor notExample x = [1, 2, 3, 4, 5]a = 3print(a in x)Returns True, if the item is foundin the listExample x = [1, 2, 3, 4, 5]a = 7print(a not in x)Returns True, if the item is notfound in the list](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-9-2048.jpg&f=jpg&w=240)
![ListAliasing And Cloning ListsAliasing: Giving new name for the existing listExample x = [10, 20, 30, 40]y = xNote: No separate memory will be allocated for yCloning / Copy: Making a copyExample x = [10, 20, 30, 40]y = x[:] <=> y = x.copy()x[1] = 99print(x)print(y)Note: Changes made in one list will not reflect other](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-10-2048.jpg&f=jpg&w=240)

![ListTo find the common items#To find the common item in two listsl1 = ["Thomas", "Richard", "Purdie", "Chris"]l2 = ["Ram", "Amar", "Anthony", "Richard"]#Covert them into setss1 = set(l1)s2 = set(l2)#Filter intersection of two setss3 = s1.intersection(s2)#Convert back into the listcommon = list(s3)print(common)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-12-2048.jpg&f=jpg&w=240)
![ListNested List#To create a list with another list as elementlist = [10, 20, 30, [80, 90]]print(list)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-13-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-1: Create a list with squares of integers from 1 to 10#Version-1squares = []for x in range(1, 11):squares.append(x ** 2)print(squares)#Version-2squares = []squares = [x ** 2 for x in range(1, 11)]print(squares)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-14-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-2: Get squares of integers from 1 to 10 and take only the even numbers from theresulteven_squares = [x ** 2 for x in range(1, 11) if x % 2 == 0]print(even_squares)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-15-2048.jpg&f=jpg&w=240)
![ListList ComprehensionsExample-3: #Adding the elements of two list one by one#Example-1x = [10, 20, 30]y = [1, 2, 3, 4]lst = []#Version-1for i in x:for j in y:lst.append(i + j)#Version-2lst = [i + j for i in x for j in y]#Example-2lst = [i + j for i in "ABC" for j in "DE"]print(lst)List comprehensions represent creation of new lists from an iterable object(list, set,tuple, dictionary or range) that satisfies a given condition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-16-2048.jpg&f=jpg&w=240)


![TupleCreating TuplesTo create empty tupletup1 = ()Tuple with one itemtup1 = (10, )Tuple with different dtypestup3 = (10, 20, 1.1, 2.3, "Ram", 'M')Tuple with no bracest4 = 10, 20, 30, 40Create tuple from the listlist = [10, 1.2, "Ram", 'M']t5 = tuple(list)Create tuple from ranget6 = tuple(range(4, 10, 2))](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2flisttuples-190509113138%2f75%2fPython-programming-List-and-tuples-19-2048.jpg&f=jpg&w=240)





Introduction to collections in Python, focusing on Lists and Tuples.
Detailed explanation of Lists including creation, indexing, types, concatenation, repetition, and membership.
Operations on lists such as updating, deleting, cloning, and aliasing.
Practical exercises for finding maximum/minimum items, common elements, and sorting.
Introduction to Nested Lists and List Comprehensions for efficient list creation.
Basic introduction to Tuples, highlighting their immutability and similarities to Lists.
Creating, accessing, performing operations, and processing functions on Tuples.
Closing remarks and acknowledgments.