[ Write a program to print Maximum frequency character in String ]
Write a program to print Maximum frequency character in String
# initializing string
test_str = "Helloworld"
print ("The original string is : " + test_str)
all_freq = {}
for i in test_str:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
res = max(all_freq, key = all_freq.get)
print ("The maximum of all characters in Helloworld is : " + str(res))
Write a program to check if a string contains any special character
import re
def run(string):
regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if(regex.search(string) == None):
print("String is accepted")
else:
print("String is not accepted.")
if __name__ == '__main__' :
# Enter the string
string = "Hello@World"
# calling run function
run(string)
Write a program to check if a string is binary or not
def check(string) :
p = set(string)
s = {'0', '1'}
if s == p or p == {'0'} or p == {'1'}:
print("Yes")
else :
print("No")
# driver code
if __name__ == "__main__" :
string = "101010000111"
check(string)
Write a program to check whether a given string is Heterogram or not
def heterogram(input):
alphabets = [ ch for ch in input if ( ord(ch) >= ord('a') and ord(ch) <= ord('z') )]
if len(set(alphabets))==len(alphabets):
print ('Yes')
else:
print ('No')
# Driver program
if __name__ == "__main__":
input = 'Hello World'
heterogram(input)
write a program to check whether a given key already exists in a dictionary.
def checkKey(dict, key):
if key in dict.keys():
print("Present, ", end =" ")
print("value =", dict[key])
else:
print("Not present")
# Driver Code
dict = {'a': 100, 'b':200, 'c':300}
key = 'b'
checkKey(dict, key)
key = 'w'
checkKey(dict, key)
write a program to check whether the string is a palindrome or not
def isPalindrome(s):
return s == s[::-1]
s = "malayalam"
ans = isPalindrome(s)
if ans:
print("Yes")
else:
print("No")