number of similar elements present in the last. List.count(value) MyList=[ , , ] x = MyList.count( ) print(x) Output: index ( ) Returns the index value of the first recurring element List.index(element) MyList=[ , , ] x = MyList.index( ) print(x) Output: reverse ( ) Reverses the order of the element in the list. List.reverse( ) MyList=[ , , ] MyList.reverse() print(MyList) Output: [ , , ] sort ( ) Sorts the element in list List.sort(reverse=True|False, key=myFunc) Both arguments are optional • If reverse is set as True, list sorting is in descending order. • Ascending is default.
• Key=myFunc; “myFunc” - the name of the user defined function that specifies the sorting criteria. Note: sort( ) will affect the original list. MyList=['Thilothamma', 'Tharani', 'Anitha', 'SaiSree', 'Lavanya'] MyList.sort( ) print(MyList) MyList.sort(reverse=True) print(MyList) Output: ['Anitha', 'Lavanya', 'SaiSree', 'Tharani', 'Thilothamma'] ['Thilothamma', 'Tharani', 'SaiSree', 'Lavanya', 'Anitha'] 12th Computer Chapter - - max( ) Returns the maximum value in a list. max(list) MyList=[ , , , ] print(max(MyList)) Output: min( ) Returns the minimum value in a list.
min(list) MyList=[ , , , ] print(min(MyList)) Output: sum( ) Returns the sum of values in a list. sum(list) MyList=[ , , , ] print(sum(MyList)) Output: . . Programs using List divBy4=[ ] for i in range( ): if (i% == ): divBy4.append(i) print(divBy4) Output [ , , , , , ] Program : write a program that creates a list of numbers from to that are divisible by country=["India", "Russia", "Srilanka", "China", "Brazil"] = input("Enter the name of the country: ") if in country: print( , " is the member of BRICS") else: print( , " is not a member of BRICS") Output Enter the name of the country: India India is the member of BRICS Output Enter the name of the country: Japan Japan is not a member of BRICS Program : Write a program to define a list of countries that are a member of BRICS.
Check whether a county is member of BRICS or not 12th Computer Chapter - - Lists, Tuples, Sets and Dictionary marks=[] subjects=['Tamil', 'English', 'Physics', 'Chemistry', 'Comp. Science', 'Maths'] for i in range( ): m=int(input("Enter Mark