def addWord(D,s,pos,v):
    #extract string of word from the sentence
    word = s[pos]
    #base case. v is 0, so we're just returning D with the frequency of s[w] incremented, not altering subdictionaries
    if v == 0:
        # increment the frequency if the word already exists
        if D in word:
            D[word] =(D[word][freq]+1,D[word][sub1],D[word][sub2])
        # otherwise, create a new entry in D
        else:
            D[word] =(1,{},{})
        return D

    # if v is greater than 0, we increment the frequency and ask for subdictionaries
    elif v>0:
        if word in D:
            newsub1 = D[word][sub1]
            if pos < len(s)-1:
                newsub1 = addWord(D[word][sub1],s,pos+1,v-1)

            newsub2 = D[word][sub2]
            if v>1 and pos < len(s)-2:
                newsub2 = addWord(D[word][sub2],s,pos+2,v-2)

            D[word] =(D[word][freq]+1,newsub1,newsub2)
            return D
        else:
            D[word] =(1,{},{})

            newsub1 = {}
            if pos < len(s)-1:
                newsub1 = addWord(D[word][sub1],s,pos+1,v-1)

            newsub2 = {}
            if v>1 and pos < len(s)-2:
                newsub2 = addWord(D[word][sub2],s,pos+2,v-2)


            D[word] =(D[word][freq]+1,newsub1,newsub2)
            return D

# given a dictionary of keys with freqs in position [0], returns a dictionary with these frequencies rescaled to sum to 1
# calls itself on all subdictionaries
dataset/ETHPy150Open jbrew/pt-write/pt-write.py/addWord/swapped operands of `in`