• CheckiO Weekly #1 ― Pangram Review

Hello, CiO People!

Today I would examine the fresh CheckiO mission "Pangram". This mission was based on an idea by Sim0000, which had added to a recent forum post. You can propose your own ideas there too and we will try to make them happen.

A pangram is a sentence which uses every letter of the alphabet at least once. In this mission you need to check text and verify if the given sentence is a pangram for the English alphabet or not.

There are many methods which can be employed to solve this problem. As we can see, it's easy to write a solution with a time complexity of O(N), you just use hash table data types to solve the problem. However, we will not stop at this and will looking for more interesting solutions which were made by CheckiO players.

Clear

The first solution we'll look at is titled "First" and was created by dagger126 with a simple and obvious solution. There's a good usage of the built-in set data type.

from string import ascii_lowercase​
​
def check_pangram(text):
    return set(ascii_lowercase).issubset(set(text.lower()))

Here's an alternate method by DmitriyS titled "all() + string.ascii_lowercase" As we can see from the title, this uses the "all" function with comprehension. It iterates all of the letters in the alphabet and check if they are in the given text.

def check_pangram(text):
    text = text.lower()
    return all(c in text for c in string.ascii_lowercase)

We have another "First" by saklar13 this time. This solution presents a nice way to solve our problem without using the alphabet, but with rather the str.isalpha method.

check_pangram = lambda text: len({x for x in text.lower() if x.isalpha()}) == 26

Creative

At the top of the creative category, we have the "65" solution by DiZ. Looks like a code golf solution with double meaning using "65"! ;-)

check_pangram=lambda t:set(map(chr,range(65,91)))<=set(t.upper())

"Not Very Clean but works" by schanjr is "the most complicated solution of the task" as community member veky puts it. But this solution has made it in the "Creative" category, so I'm sure schanjr made something special. The solution has 20 strings, but this line should be especially noted:

...
if all(x is x>=2 for x in count.itervalues()):
...

This comment about using if-else for returns can be useful for newbies. In it, Veky explains the best practices.

If we would make an award for "the most complicated solution for a task", then I would nominate "First | Naive" by bundgaard.

And

We often meet solutions which are written with Python but are not "in" Python - sometimes they use a LISP or Java style of coding for example. When I first started to learn Pythonm for example, I wrote C-code with Python syntax. Python gurus often found this style of code funny to read.

So, how about trying to write a "Pangram" solution with Python, but not in the Python style? Could you do it?

Become Awesome

  • No Ads
  • No Limits
  • More Content

Welcome to CheckiO - games for coders where you can improve your codings skills.

The main idea behind these games is to give you the opportunity to learn by exchanging experience with the rest of the community. Every day we are trying to find interesting solutions for you to help you become a better coder.

Join the Game