# ACT 2-6

# from http://finance.yahoo.com/news/25-worst-passwords-2011-revealed-202955980.html
passwordDictionary = {'Alice':'password',
                      'Bob': '123456',
                      'Carol':'12345678',
                      'Deb':'qwerty',
                      'Emma':'abc123',
                      'Florence':'letmein',
                      'Gary':'trustno1',
                      'Hillary':'dragon',
                      'Ingrid':'baseball',
                      'Jeremy':'111111',
                      'Kyle':'iloveyou',
                      'Lou':'master',
                      'Mary':'sunshine',
                      'Ned':'ashley',
                      'Owen':'bailey',
                      'Pat':'passw0rd',
                      'Quintin':'shadow',
                      'Ryan':'123123',
                      'Sandra':'654321',
                      'Trevor':'superman',
                      'Uma':'qazwsx',
                      'Valerie':'michael',
                      'Wilbur':'football'}

# Task 1
def printDictionary(dictionary):
    '''Prints the dictionary key-value pairs from a dictionary.'''
    keyList = dictionary.keys();
    for key in keyList:
        print key,' -> ',dictionary[key]
    return

# Task 2
def echo():
    myInput = raw_input('write something and hit Enter: ')
    print 'You wrote:',myInput
    return

def addPassword(dictionary,key,value):
    '''Adds the (key,value) pair to the dictionary and returns the new dictionary'''
    print 'Changing Password.'
    dictionary[key] = value
    return dictionary

# Task 3
def nameGame(name):
    '''Given a name, returns a verse.'''
    name = name.lower()
    c = name[0] # c is the first character of the name.  Check if it's a vowel.
    if (c == 'a') or (c == 'e') or (c == 'i') or (c == 'o') or (c == 'u'):
        suffix = name
    else:
        suffix = name[1:len(name)]
        
    myStr = name + ' ' + name + ' bo b' + suffix + '\n'
    myStr = myStr + 'banana fana fo f' + suffix + '\n'
    myStr = myStr + 'me mi mo m' + suffix + '\n'
    myStr = myStr + name
    return myStr

# Task 4
# The import statement below tells Python to load a
# set of 'regular expression' functions.  Usually
# import statements such as this are placed at the TOP
# of the file.
import re

def readShel():
    '''Reads the shel poem and returns a string'''
    fileName = 'poem.txt'
    myFile = open(fileName,'r')
    myString = myFile.read()
    myFile.close()
    return myString

def printRegEx(regex,myString):
    '''Prints all occurrences of the regular expression.'''
    iterator = re.finditer(regex,myStr) # NEW object! It's called an iterator.
    for i in iterator:
        print 'matches',i.group(),'at positions',i.start(),'-',i.end()
    return
