Skip to content

Latest commit

 

History

History
14 lines (13 loc) · 358 Bytes

File metadata and controls

14 lines (13 loc) · 358 Bytes

Dictionary: Some useful piece of Code during programming

Counting the occurrence of elements

from collections import Counter
def occurrence(s: str) -> dict:
    """
    s can be list/string/tuple
    It will return a dictionary with key as elements and value as their 
    number of occurrences
    """
    d = Counter(s)  
    return d