6.10 typing פתרון

from typing import List, Tuple, Dict

def process_data(data: List[Tuple[str, int]]) -> Dict[str, int]:
    """
    Process a list of tuples containing a string and an integer.
    Returns a dictionary where the keys are strings and the values are integers.
    """
    result: Dict[str, int] = {}
    for item in data:
        key, value = item
        if key not in result:
            result[key] = value
        else:
            result[key] += value
    return result

def display_results(results: Dict[str, int]) -> None:
    """
    Display the results from processing the data.
    """
    print("Processed Results:")
    for key, value in results.items():
        print(f"{key}: {value}")

def main() -> None:
    """
    Main function to orchestrate the processing of data.
    """
    data: List[Tuple[str, int]] = [("apple", 5), ("banana", 3), ("apple", 2), ("orange", 4)]
    processed_data: Dict[str, int] = process_data(data)
    display_results(processed_data)

if __name__ == "__main__":
    main()