handro33 / pwp-capstones

0 stars 0 forks source link

n_gram_creator loop #1

Open ad3429 opened 6 years ago

ad3429 commented 6 years ago

Another way to write the loop using a for each instead of a standard for loop would be:

def ngram_creator(text_list):
    ngrams   = []
    lastword = None

    for word in text_list:
        if lastword:
            ngrams.append('{} {}'.format(lastword, word))
        lastword = word
    return ngrams
handro33 commented 6 years ago

Wow that is so much easier. I had a hard time remember so much of the text/string lessons. Even just a week between doing the main lessons and the capstone put a damper on how to implement.

Thanks