def sumList(lst):
if lst == []:
return 0
else:
return lst[0] + sumList(lst[1:])
sumList([1,2,3,4,5,6,7,8,9,10])
def evenList(lst):
if lst == [ ]:
return [ ]
elif lst[0]%2==0:
return [lst[0]]+evenList(lst[1:])
else:
return evenList(lst[1:])
evenList([3,5,6,3,22,45,34])
def revList(lst):
if lst==[]:
return []
else:
return revList(lst[1:]) + [lst[0]]
revList([3,5,6,3,22,45,34])
def is_palindrome(str1):
if len(str1) == 0 or len(str1) == 1:
return True
elif str1[0]!=str1[-1]:
return False
else:
return is_palindrome(str1[1:-1])
is_palindrome("race car")
# remove spaces from a string
def removespaces(str1):
s = str1.replace(" ", "")
return s
#a fucntion which removes spaces and then checks if a string is a palindrome
# Print appropriate messgaes when you find a palindrome
def palindrome(str1):
str1 = removespaces(str1)
print(str1)
if is_palindrome(str1):
print ("Hey!! we have a palindrome")
else:
print ("Sorry we dont have a palindrome")
removespaces("madam im adam")
palindrome("madam im adam")