## Python String Methods

capitalize() Converts the first character to upper case casefold() Converts string into lower case center() Returns a centered string count()         Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value…

## Solution Exercise 22: python algorithm which determines the list of duplicate elements

Exercise 22 Write an algorithm in python that returns the list of duplicate elements of a given list without using any predefined functions in Python. Example if L = [7, 23, 5, 12, 7, 19, 23, 12, 29], the algorithm returns the list [7, 23, 12]. Solution def listDuplicate (L): # initialization of the list…

## Solution Exercise 12: maximum and minimum of a Python list

Exercise 12 Using the sort () method, write an algorithm in python as a function which takes as parameter a list L of numbers and which returns the couple (min, max) formed by the minimum and the maximum of the list. Solution def minMax(L): # sorting the liste L.sort() return (L[0] , L[-1])# ExempleL =…

## Solution Exercise 11: Multiply the elements of a Python list by a given integer

Exercise 11 Write an algorithm in python as a function which takes as parameter a tuple (L, n) formed by a list L of numbers and an integer n and which returns the list obtained from L by multiplying its elements by n . Example if L = [3, 9, 5, 23] and n =…

## Solution Exercise 10: python algorithm that returns the position of an element in a given list

Exercise 10 Write an algorithm in python as a function which takes as a parameter a tuple (L, x) formed by a list L and an element x and which returns the position of the element x in the list L. The function must return -1 if element x is not in the list. Solution…

## Solution Exercise 9: python algorithm which tests if an element is present in a list or not

Exercise9 Write an algorithm in python as a function which takes as parameter a tuple (L, a) formed by a list L and an element a and which returns True if the element a is present in the list L and False if no. Solution def examineList (L, a): if a in L: return True…

## Solution Exercise 8: python algorithm which calculates the average of the elements of a given list

Exercise8 Write an algorithm in python that returns the average of the terms in a list of numbers. Solution def averageList (L): # initialization of the average m = 0 for x in L: m = m + x # average = sum of the elements of L / length of L m = m…