Sorting elements of an Array by Frequency

    0

    0

    CrypticSai-08

    from collections import Counter
    ini_list = [10, 20, 30, 40, 40, 50, 50, 50]
    # sorting on bais of frequency of elements
    result = [item for items, c in Counter(ini_list).most_common() for item in [items] * c]
    # printing final result
    print(str(result))
    
    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.