# WAP IN PYTHON TO FIND THE SECOND OCCURRENCE OF THE GIVEN SUBSTRING FROM THE MAIN STRING. """ s = "Python Is Easy Programming Language" sub = 'a' """ def findPosition(string, sub): return string.find(sub,string.find(sub) + 1) string = input("Enter a string:") sub = input("Enter the sub-string:") print("The Second occurrence at = ",findPosition(string,sub)) ======================================================================== # WAP TO PRINT ALL PRIME NUMBERS FROM 100 TO 200. def primeNUmberPrinting(number): if number < 2: return False for i in range(2,int(number ** 0.5) + 1): if number % i == 0: return False return True primeNUmber = [n for n in range(100,201) if primeNUmberPrinting(n)] print("All Prime Numbers = ",primeNUmber) ==================================================== List Data structure: ==================== # About the list # list can be defined with [] a = [] # without any member ==> empty list print(type(a)) # list can be homogeneous b = [1,3,5,7,9] # list with integers c = [0.1,0.01,0.001,0.0001] # list with floats # list can be heterogeneous d = [101,1.001,1-2j,True,'abcd'] # list is ordered. print(b) print(c) print(d) # List can be indexed. print(b[0],b[1],b[2],b[3],b[4]) # positive index print(b[-5],b[-4],b[-3],b[-2],b[-1]) # negative index # Slicing is allowed for the list print(b[::1]) print(b[::-1]) print(c[1:4]) ========================================== # Membership Check of list """ membership operators in ==> True or False not in ==> True or False """ l = [100,300,500,700,900] a = 110 if a in l: print("Yes ",a,"is the member of the list.") else: print("Yes ", a, "is the not member of the list.") ================================================================ Finding Length of the list: =========================== # finding length of the list l = [1,2,3,4,5,6,7,8,9,10,1,3,5,7,9,2,4,6,8,10] # list can be duplicated # approach-1: using built-in method """ len() Syntax: len(any collection) """ print("The Length = ",len(l)) # approach-2: without using built-in method # traversing/looping count = 0 for i in l: count += 1 print("The Length of the List = ",count) ====================================================== # other ways to define the list # list definition in compile time a = [1,2,3,4,5,6] # compile time definition # list in run time """ eval() """ b = eval(input("Enter a list:")) print(a,type(a)) print(b,type(b)) # string to list # any other collection to list # list() c = list("Python") d = list((1,3,5,7,9,2,4,6,8,10)) print(c,type(c)) print(d,type(d)) e = "26-11-2024" ld = e.split('-') print(e) print(ld) ================================================= List is Mutable data: ===================== Mutable ==> we can able to modify after the definition within the same address location. ld = list("Python") print(ld) print(id(ld)) ld[0] = 'p' print(ld) print(id(ld)) ======================================= # counting the number of occurrences of list element. # count() """ Syntax: list-object.count(list-element) """ ld = eval(input("Enter a list:")) print("The Number of occurrences = ") # for i in ld: # print(i," = ",ld.count(i)) print(ld.count(1000)) ================================================= # append() ==> can allow to add the element at the end of the list automatically. ld = [] print("The List = ",ld) ld.append(100) ld.append(1000) ld.append(10000) print(ld) # insert() ==> can able to insert the element at the specified index. if the specified index is from out # of range , insert() can add at the last automatically. ld.insert(0,10) ld.insert(2,11001) ld.insert(10,112233) print(ld) # extend() ld1 = ['a','e','i','o','u'] print(ld1) ld1.extend(ld) print(ld) print(ld1) ========================================================== # delete operations # remove() ==> to make remove the specified element, remove() can be used. ld = [10,100,100,1111,111,11,1] print(ld) ld.remove(111) print(ld) # ld.remove(11,1) # ld.remove(1011) # note: no method can able to remove more than one value # pop() ==> can always able to remove the last element only. ld.pop() print(ld) ld.pop() print(ld)