import re   # must-have if you want to use regular expressions

#TODO: modify this function so that it performs according to its specification.
def build_concordance(string):
    ''' Given a string, returns a dictionary that maps words in the string to lists of integers.
    The integers are positions of the occurrences of that word in the string.'''
    
    concordance = {}    # start with a
    
    string = string.lower()
    
    iter = re.finditer(r"\w+", string)  # I am searching for all the English words. Do not worry about the r in front of the string
    for i in iter:  # iterate through all matches I've found
        word = i.group(0)   # this is how you get the matched string
        position = i.start(0)   # this is how you get the position where it is matched
        print(word, position)   # this is how I print two things on the same line

    return concordance

            
#TODO: implement this function
def print_concordance(word, concord, text):
    ''' Given a word, a concordance (dictionary) and the original text,
    Prints all occurrences of the word with surrounding contexts.'''
    return

# Testing...
s = '''Call me Ishmael.  Some years ago--never mind how long precisely--
having little or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail about a little
and see the watery part of the world.
'''

# read something interesting from a file into s when you are ready to test on big texts
# such as the following line
#s = open('Z:/WinData/Desktop/MobyDick.txt').read()

conc = build_concordance(s)
print_concordance('I', conc, s)

