Skip to main content
edited body
Source Link
Janne Karila
  • 10.7k
  • 21
  • 34

Since you do not actually need the count of each character, it would be simpler to use a set and the superset operator >=:

def is_pangram(astr):
    return set(astr.lower()) >= set(string.ascii_lowercase):

Your two solutions are almost identical, though here
for char in astr:
    lookup[char.lower()] += 1  

it would be faster to lowercase the whole string at once (like you already do in solution 2):

for char in astr.lower():
    lookup[char] += 1  

Other than that, the only difference is defaultdict vs. Counter. The latter makes your code more elegant, but since the standard library implements Counter in pure Python, there may be a speed advantage to defaultdict.

Since you do not actually need the count of each character, it would be simpler to use a set and the superset operator >=:

def is_pangram(astr):
    return set(astr.lower()) >= set(string.ascii_lowercase):

Since you do not actually need the count of each character, it would be simpler to use a set and the superset operator >=:

def is_pangram(astr):
    return set(astr.lower()) >= set(string.ascii_lowercase):

Your two solutions are almost identical, though here
for char in astr:
    lookup[char.lower()] += 1  

it would be faster to lowercase the whole string at once (like you already do in solution 2):

for char in astr.lower():
    lookup[char] += 1  

Other than that, the only difference is defaultdict vs. Counter. The latter makes your code more elegant, but since the standard library implements Counter in pure Python, there may be a speed advantage to defaultdict.

edited body
Source Link
Janne Karila
  • 10.7k
  • 21
  • 34

Since you do not actually need the count of each character, it would be simpler to use a set and the superset operator >=:

def is_pangram(astr):
    return set(astr.lower()) ==>= set(string.ascii_lowercase):

Since you do not actually need the count of each character, it would be simpler to use a set:

def is_pangram(astr):
    return set(astr.lower()) == set(string.ascii_lowercase):

Since you do not actually need the count of each character, it would be simpler to use a set and the superset operator >=:

def is_pangram(astr):
    return set(astr.lower()) >= set(string.ascii_lowercase):
Source Link
Janne Karila
  • 10.7k
  • 21
  • 34

Since you do not actually need the count of each character, it would be simpler to use a set:

def is_pangram(astr):
    return set(astr.lower()) == set(string.ascii_lowercase):