Skip to main content
s/letters/ascii_lowercase
Source Link
kojiro
  • 1.8k
  • 1
  • 13
  • 22

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

from __future__ import with_statement
import sys
from string import lettersascii_lowercase
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower()ascii_lowercase)

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

from __future__ import with_statement
import sys
from string import letters
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower())

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

from __future__ import with_statement
import sys
from string import ascii_lowercase
filepath = sys.argv[1]
wholealphabet = frozenset(ascii_lowercase)

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

Future import needs to go at the top.
Source Link
kojiro
  • 1.8k
  • 1
  • 13
  • 22

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

import sys
from __future__ import with_statement
import sys
from string import letters
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower())

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

import sys
from __future__ import with_statement
from string import letters
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower())

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

from __future__ import with_statement
import sys
from string import letters
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower())

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)

Source Link
kojiro
  • 1.8k
  • 1
  • 13
  • 22

One of Python's greatest strengths is its built-in capability to use sets directly. I don't feel you've used sets to their fullest extent here. I'd also like to point out the with statement, which you should probably use to handle file handles.

import sys
from __future__ import with_statement
from string import letters
filepath = sys.argv[1]
wholealphabet = frozenset(letters.lower())

# Use with to handle file … handles
with open(filepath) as f:
    for line in f: # assume a line is a sentence, not exactly per spec?
        # sortedletters = list(set(line.lower())) # guaranteed to be *unsorted*
        missingletters = wholealphabet.difference(line.lower())
        if missingletters:
            print ''.join(sorted(missingletters))
        else:
            print 'NULL'

That's really all you need. Unless you want to reconsider the definition of a sentence. :)