Rajesh
BAN USERI will give a solution using Python.
Let's say you have an array of integers named "arr".
dic = {i:arr.count(i) for i in set(arr)}
sorted(dic.items(), key=lambda x: x[1])[-2][0]
This will give the second most repeating number in arr.
If this is not the solution you are looking for, please let me know.
Another solution in Python:
Please provide if you have better solutions.
def ispalindrome(word):
n = len(word)
lowerword = word.lower()
dictcount = {i:lowerword.count(i) for i in set(lowerword)}
oddCount = 0
if n%2 == 0:
for key in dictcount.keys():
if dictcount[key] % 2 != 0:
return False
else:
for key in dictcount.keys():
if dictcount[key] % 2 != 0:
oddCount += 1
if oddCount > 1:
return False
else:
return True
def main():
word = raw_input("Enter the word : ")
if ispalindrome(word):
print "True"
else:
print "False"
if __name__ == '__main__':
main()
Output:
>python palindrome.py
Enter the word : mmo
True
Enter the word : yakak
True
Enter the word : travel
False
Hope you like this:
- Rajesh April 11, 2015