#!/usr/bin/env python import sys, fileinput def dropcaps(lines): words = set() result = set() for line in lines: word = line.rstrip('\r\n') capword = word.capitalize() words.add(word) result.add(word) if word != capword: # If the word is lower case if capword in words: # If the word was in its upper case form result.discard(capword) # Remove the capital case word if word == capword: # If the word is capital case if word in words: # If the word was in its lower case form result.discard(capword) # Remove the capital case word for word in result: print word def main(): args = sys.argv[1:] lines = fileinput.input(args or ['-']) dropcaps(lines) if __name__=="__main__": main()