Word Occurrence

    0

    0

    HARIGOVIND VALSAKUMAR

    PythonWordOccurence
    HGV Public Cookbook

    Function to count the occurrences of all words in a sentence

    from collections import defaultdict
    
    def word_occurence(sentence):
        occurrence = defaultdict(int)
        for word in sentence.split():
            occurrence[word] += 1
        return occurrence
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.