Skip to main content
Source Link
Nevpzo
  • 187
  • 3
  • 16

I chose to use Python as it is the language i'm most familiar with. To check if a string is a pangram, I removed every special caracter and spaces, then removed the alphabet from it. If there is nothing leftover, the string is a pangram (P) and to be a perfect pangram (PP), it has to contain each letter only once so its length must be 26. If there's something leftover, then the test string did not contain all the alphabet letters, so it must not be a pangram (False). I then apply the function to every element of the file and store the information in a dictionnary to simplify counting.

import json

with open("CodingChallenge/List of 1000 strings.json", "r") as f:
    Strings = json.load(f)

def is_pangram(s):
    s = ''.join(e for e in s if e.isalnum())
    if not set('abcdefghijklmnopqrstuvwxyz') - set(s.lower()):
        if len(s) == 26:
            return 'PP'
        return 'P'
    else:
        return False

pangrams = {'PP': 0, 'P': 0, False: 0}

for s in Strings:
    type = is_pangram(s)
    if type == 'PP':
        pangrams['PP'] += 1
    elif type == 'P':
        pangrams['P'] += 1
    else:
        pangrams[False] += 1

print(pangrams)

Output:

{'PP': 49, 'P': 132, False: 819}