Saturday, September 30, 2023
HomeSoftware EngineeringDiscover the Lacking Alphabets in Python

Discover the Lacking Alphabets in Python


The problem

Activity

Given string s, which comprises 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 seek out the lacking letter(s). You might have to output them by the order a-z. It’s doable that there’s a couple of lacking letter from a couple of set of alphabet.

If the string comprises the entire letters within the alphabet, return an empty string ""

Instance

For s="abcdefghijklmnopqrstuvwxy"

The outcome must be 'z'

For s="aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"

The outcome must be 'zz'

For s="abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"

The outcome must be 'ayzz'

Enter/Output

Given string(s) comprises 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

Choice 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)

Choice 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'))

Choice 3:

def missing_alphabets(s):
    doc = {e:s.depend(e) for e in 'abcdefghijklmnopqrstuvwxyz'}
    mx  = max(doc.values())
    return ''.be a part of(ok * (mx - v) for ok,v in doc.objects() if v < mx)

Check instances to validate our resolution

check.it("Primary Exams")
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")
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments