Skip to main content

Panagrams Pangrams CodeEval challenge

deleted 28 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

First attempt at Python would really apreciate a review Panagrams CodeEval challenge

This is my first attempt at programming in python, I took a challenge on CodeEval http://www.codeeval.com/open_challenges/37/CodeEval

Tough. Although the code seems to work for the examples taken from the site, I feel it is not really pretty and must be more complicated than it should be.

Pangrams

Description:

The sentence 'A quick brown fox jumps over the lazy dog' contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL

Description:

The sentence 'A quick brown fox jumps over the lazy dog' contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL.

import sys
filepath = sys.argv[1]
f = open(filepath)
wholealphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
                 's','t','u','v','w','x','y','z')
for line in f:
    sortedletters = list(set(line.lower()))
    i = 0
    while i != len(sortedletters):
        if wholealphabet.count(sortedletters[i]) != 0: 
            i = i + 1
        else:
            sortedletters.pop(i)
    missingletters = ""
    for letter in wholealphabet:
        if sortedletters.count(letter) == 0:
            missingletters +=letter
    if len(missingletters) == 0:
        print("NULL")
    else:
        print(missingletters)

First attempt at Python would really apreciate a review

This is my first attempt at programming in python, I took a challenge on CodeEval http://www.codeeval.com/open_challenges/37/

Tough the code seems to work for the examples taken from the site I feel it is not really pretty and must be more complicated than it should be.

Pangrams

Description:

The sentence 'A quick brown fox jumps over the lazy dog' contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL

import sys
filepath = sys.argv[1]
f = open(filepath)
wholealphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
                 's','t','u','v','w','x','y','z')
for line in f:
    sortedletters = list(set(line.lower()))
    i = 0
    while i != len(sortedletters):
        if wholealphabet.count(sortedletters[i]) != 0: 
            i = i + 1
        else:
            sortedletters.pop(i)
    missingletters = ""
    for letter in wholealphabet:
        if sortedletters.count(letter) == 0:
            missingletters +=letter
    if len(missingletters) == 0:
        print("NULL")
    else:
        print(missingletters)

Panagrams CodeEval challenge

I took a challenge on CodeEval. Although the code seems to work for the examples taken from the site, I feel it is not really pretty and must be more complicated than it should be.

Description:

The sentence 'A quick brown fox jumps over the lazy dog' contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL.

import sys
filepath = sys.argv[1]
f = open(filepath)
wholealphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
                 's','t','u','v','w','x','y','z')
for line in f:
    sortedletters = list(set(line.lower()))
    i = 0
    while i != len(sortedletters):
        if wholealphabet.count(sortedletters[i]) != 0: 
            i = i + 1
        else:
            sortedletters.pop(i)
    missingletters = ""
    for letter in wholealphabet:
        if sortedletters.count(letter) == 0:
            missingletters +=letter
    if len(missingletters) == 0:
        print("NULL")
    else:
        print(missingletters)
Tweeted twitter.com/#!/StackCodeReview/status/140707099209498624
Source Link
Tommy
  • 225
  • 2
  • 7

First attempt at Python would really apreciate a review

This is my first attempt at programming in python, I took a challenge on CodeEval http://www.codeeval.com/open_challenges/37/

Tough the code seems to work for the examples taken from the site I feel it is not really pretty and must be more complicated than it should be.

Pangrams

Description:

The sentence 'A quick brown fox jumps over the lazy dog' contains every single letter in the alphabet. Such sentences are called pangrams. You are to write a program, which takes a sentence, and returns all the letters it is missing (which prevent it from being a pangram). You should ignore the case of the letters in sentence, and your return should be all lower case letters, in alphabetical order. You should also ignore all non US-ASCII characters.In case the input sentence is already a pangram, print out the string NULL

import sys
filepath = sys.argv[1]
f = open(filepath)
wholealphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
                 's','t','u','v','w','x','y','z')
for line in f:
    sortedletters = list(set(line.lower()))
    i = 0
    while i != len(sortedletters):
        if wholealphabet.count(sortedletters[i]) != 0: 
            i = i + 1
        else:
            sortedletters.pop(i)
    missingletters = ""
    for letter in wholealphabet:
        if sortedletters.count(letter) == 0:
            missingletters +=letter
    if len(missingletters) == 0:
        print("NULL")
    else:
        print(missingletters)