The problem
Activity
Given string s
, which incorporates solely letters from a to z
in lowercase.
A set of the alphabet is given by abcdefghijklmnopqrstuvwxyz
.
2 units of alphabets imply 2 or extra alphabets.
Your activity is to search out the lacking letter(s). Chances are you’ll have to output them by the order a-z. It’s doable that there’s multiple lacking letter from multiple set of alphabet.
If the string incorporates all the letters within the alphabet, return an empty string ""
Instance
For s="abcdefghijklmnopqrstuvwxy"
The end result needs to be 'z'
For s="aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"
The end result needs to be 'zz'
For s="abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"
The end result needs to be 'ayzz'
Enter/Output
Given string(s) incorporates a number of units of alphabets in lowercase.
Discover the letters contained in every alphabet however not within the string(s). Output them by the order a-z
. If the lacking alphabet is repeated, please repeat them like "bbccdd"
, not "bcdbcd"
The answer in Python code
Possibility 1:
from collections import Counter
from string import ascii_lowercase
def missing_alphabets(s):
c = Counter(s)
m = max(c.values())
return ''.be a part of(letter * (m - c[letter]) for letter in ascii_lowercase)
Possibility 2:
def missing_alphabets(s):
return ''.be a part of(sorted(c * (max(s.depend(x) for x in s) - s.depend(c)) for c in 'abcdefghijklmnopqrstuvwxyz'))
Possibility 3:
def missing_alphabets(s):
doc = {e:s.depend(e) for e in 'abcdefghijklmnopqrstuvwxyz'}
mx = max(doc.values())
return ''.be a part of(okay * (mx - v) for okay,v in doc.objects() if v < mx)
Take a look at circumstances to validate our answer
check.it("Fundamental Assessments")
check.assert_equals(missing_alphabets("abcdefghijklmnopqrstuvwxy"),"z")
check.assert_equals(missing_alphabets("abcdefghijklmnopqrstuvwxyz"),"")
check.assert_equals(missing_alphabets("aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"),"zz")
check.assert_equals(missing_alphabets("abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"),"ayzz")