'''
Created on Sep 11, 2013

@author: rcd
'''
# Same as last time -- added comments
def validatePassword(password):
    """
    >>> validatePassword('CantGuessTh1s')
    True
    
    >>> validatePassword('helloThere')
    False
    
    return a boolean
    based on string parameter password
    """
    # add your code to solve the problem after this line
    # easy out: check length
    if len(password) < 8:
        return False
    # easy out: check spaces
    if password.count(' ') > 0:
        return False
    
    # check each character for at least one of 
    # either digit or capital
    upperCount = 0
                                # "pattern" or template for "accumulation"
    
    digitCount = 0              # initialize the result
    for ch in password:         # loop
        if ch.isdigit():        # filter (optional)
            digitCount += 1     # accumulate total value
        elif ch.isupper():
            upperCount += 1

    # return True only if both were seen
    if digitCount > 0 and upperCount > 0:
        return True
    else:
        return False
    # OR:
    # return digitCount > 0 and upperCount > 0

# interactive example
print(validatePassword('hEllo1there'))

# a few examples -- in the console
examples = [ 'hello', 'helloThree', 'password', 'PassW0rd' ]
for password in examples:
    print(validatePassword(password))

# a function for CloudCoder
def validateAll (passwordList):
    results = []
    for password in passwordList:
        results += [ validatePassword(password.strip()) ]
    return results

print(validateAll(examples))

# for files
f = open("common_passwords.txt")
examples = f.readlines()
print(type(f))
print(len(examples))
print(examples)
print(validateAll(examples))
