LIST OPERATIONS: ================ REVERSING OF THE LIST: ====================== reverse(): ========= an inbuilt method which we can use to reverse the list Syntax: list-object.reverse() # Reversing of the list ld = eval(input("Enter a list:")) print("The List Before the reverse operation is:") print(ld) ld.reverse() print("The List After the reverse operation is:") print(ld) ================================================= Sorting of the list data: ========================= Sorting ==> arranging of list data in Ascending order (Low to High) or arranging of list data in Descending Order (High to Low) ex: [1,0,-1,11,-10,111] sorting ==> [-10,-1,0,1,11,111] ==> Ascending Order/Increasing Order Arrangement Forward Sorting sorting ==> [111,11,1,0,-1,-10] ==> Descending Order/Decreasing Order Arrangement Reverse Sorting Note: ==== By default, forward sorting can be performed. Forward Sorting: =============== sort(): an inbuilt method which we can use to arrange the elements in ascending order. Syntax: list-object.sort() or list-object.sort(reverse = False) # Forward Sorting ld = [1,0,-1,11,-10,111] print("The List Without Sorting is = ") print(ld) ld.sort() print("The List With Forward Sorting is = ") print(ld) ========== Reverse Sorting: ================ sort(): we can also use sort() for the reverse sorting. Syntax: list-object.sort(reverse = True) ld = [1,0,-1,11,-10,111] print("The List Without Sorting is = ") print(ld) ld.sort(reverse = True) print("The List With Reverse Sorting is = ") print(ld) ============================================== LIST ALIASING: ============== Defining the alternative name to the original list is called as "List Aliasing". List aliasing can be defined with '='. ex: a = [1,2,3,4,5] b = a ==> when the list with two names, both the names acquired the same address. id(a) = 123456 id(b) = 123456 ==> The modification/change at one object will reflect on another object. a[1] = 97 print(a) ==> [1,97,3,4,5] print(b) ==> [1,97,3,4,5] ========================================== # List Aliasing a = eval(input("Enter a list:")) # b = eval(input("Enter a list:")) b = a print(a);print(b) print(id(a));print(id(b)) a[1] = 111 print(a);print(b) b[3] = 121 print(a);print(b) ================= SBI ==> Loaning Feature() ICICI ==> Loaning Feature() ICICI = SBI when the customer, ICICI ==> Personal Loan with 1000000 Record of ICICI will maintain at SBI SBI ==> 25000000 SBI Record ===> ICICI ================================ List Cloning: ============= The change of one list object, need not reflect on another list object is called as "list cloning". Two ways for List Cloning: 1) Using Slice Operator 2) Using copy() 1) Using Slice Operator: ======================== # List Cloning using slicing x = [1,3,5,7,9] y = x[:] print(x);print(y) print(id(x));print(id(y)) x[1] = 100 print(x);print(y) y[2] = 97 print(x);print(y) ============================ 2) using copy(): =============== copy(): an inbuilt method, which we can use to copy the data from one list to another list Syntax: new-list = old-list.copy() # List Cloning with copy() x = eval(input("Enter a list:")) y = x.copy() print(id(x));print(id(y)) print(x);print(y) x[0] = 1221 print(x);print(y) y[2] = 9779 print(x);print(y) ======================================= # WAP TO DISPLAY UNIQUE VOWELS PRESENT IN THE GIVEN WORD. """ vowels ==> a,e,i,o,u word = "Object Oriented" op = unique vowels = 3 """ vowels = ['A','a','E','e','I','i','O','o','U','u'] word = input("Enter the word:") # "Object Oriented" result = list() # ['O','e','i'] for l in word: if l in vowels: if l not in result: result.append(l) print("A list with Unique Vowels = ",result) print("The Number of Unique Vowels are = ",len(result))