Skip to content
    OrderedDict@caputomarcos
    main.py
    Packager files
    poetry.lock
    pyproject.toml
    Config files
    .replit
    replit.nix
    from collections import OrderedDict
    from typing import Dict

    scores: Dict[str, int] = OrderedDict([
    ('Alice', 90),
    ('Bob', 85),
    ('Charlie', 95)
    ]
    )
    print(scores) # OrderedDict([('Alice', 90), ('Bob', 85), ('Charlie', 95)])

    # Accessing items by key
    print(scores['Alice']) # 90

    # Iterating over items in order
    for name, score in scores.items():
    print(name, score)
    # Alice 90
    # Bob 85
    # Charlie 95

    # Reversing the order
    for name, score in reversed(scores.items()):
    print(name, score)
    # Charlie 95
    # Bob 85
    # Alice 90

    # Converting to a regular dictionary
    regular_dict: Dict = dict(scores)
    print(regular_dict) # {'Alice': 90, 'Bob': 85, 'Charlie': 95}