Skip to content

No need for pass in build_frequency_table #2

Description

@jmcrey
def build_frecuency_table(corpus):
    frequency_table = {} #initialise the dictionary
    for element in corpus:
        if element in frequency_table.keys(): #if the element is already in the dictionary add 1 to the value of the key 
            frequency_table[element] += 1
            pass #when we increase the value of the counter of the key, we pass to the next word
        else: #if we don't have the element in the dictionary we create a new one and initialise the counter
            frequency_table[element] = 1
    return frequency_table

Really nice job with this function! I just wanted to point out that we don't need pass in this function. Usually, pass is used as a placeholder to avoid implementing a function. In this case, we can just remove it from our function -- the logic of the if - else statement will ensure that an element is not unnecessarily reset to 1.

In any case, this is just a suggestion; have pass in this function does no harm!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions