/**
 * This exercise focuses on utilizing for loop and dictionary methods.
 *
 * Given a dictionary, your task is to perform the following operations:
 * 1. Print all the keys in the dictionary using a for loop.
 * 2. Print all the values in the dictionary using a for loop.
 * 3. Print all the key-value pairs in the dictionary using a for loop.
 * 4. Calculate the sum of all values in the dictionary.
 * 5. Find the key of the maximum value in the dictionary.
 * 6. Create a new dictionary where the keys are the values and the values are the keys from the original dictionary.
 *
 * Complete the missing code to solve the exercise below.
 */
fun dictionaryOperations(dictionary: Map<String, Int>) {

    // 1. Print all the keys in the dictionary using a for loop.
    println("Keys:")
    for (key in dictionary.keys) {
        println(key)
    }
    println()

    // 2. Print all the values in the dictionary using a for loop.
    println("Values:")
    for (value in dictionary.values) {
        println(value)
    }
    println()

    // 3. Print all the key-value pairs in the dictionary using a for loop.
    println("Key-Value Pairs:")
    for ((key, value) in dictionary) {
        println("$key: $value")
    }
    println()

    // 4. Calculate the sum of all values in the dictionary.
    val sum = dictionary.values.sum()
    println("Sum of all values: $sum")

    // 5. Find the key of the maximum value in the dictionary.
    val maxEntry = dictionary.maxByOrNull { it.value }
    println("Key of maximum value: ${maxEntry?.key}")

    // 6. Create a new dictionary where the keys are the values and the values are the keys from the original dictionary.
    val reversedDictionary = dictionary.entries.associate { (key, value) -> value to key }
    println("Reversed Dictionary: $reversedDictionary")
}
/**
 * This exercise focuses on utilizing for loop and dictionary methods.
 *
 * Given a dictionary, your task is to perform the following operations:
 * 1. Print all the keys in the dictionary using a for loop.
 * 2. Print all the values in the dictionary using a for loop.
 * 3. Print all the key-value pairs in the dictionary using a for loop.
 * 4. Calculate the sum of all values in the dictionary.
 * 5. Find the key of the maximum value in the dictionary.
 * 6. Create a new dictionary where the keys are the values and the values are the keys from the original dictionary.
 *
 * Complete the missing code to solve the exercise below.
 */

fun dictionaryOperations(dictionary: Map<String, Int>) {
/**
 * This exercise focuses on utilizing for loop and dictionary methods.
 *
 * Given a dictionary, your task is to perform the following operations:
 * 1. Print all the keys in the dictionary using a for loop.
 * 2. Print all the values in the dictionary using a for loop.
 * 3. Print all the key-value pairs in the dictionary using a for loop.
 * 4. Calculate the sum of all values in the dictionary.
 * 5. Find the key of the maximum value in the dictionary.
 * 6. Create a new dictionary where the keys are the values and the values are the keys from the original dictionary.
 *
 * Complete the missing code to solve the exercise below.
 */

fun dictionaryOperations(dictionary: Map<String, Int>) {

    // 1. Print all the keys in the dictionary using a for loop.
    println("Keys:")
    for (key in dictionary.keys) {
        println(key)
    }
    println()

    // 2. Print all the values in the dictionary using a for loop.
    println("Values:")
    for (value in dictionary.values) {
        println(value)
    }
    println()

    // 3. Print all the key-value pairs in the dictionary using a for loop.
    println("Key-Value Pairs:")
    for ((key, value) in dictionary) {
        println("$key: $value")
    }
    println()

    // 4. Calculate the sum of all values in the dictionary.
    val sum = dictionary.values.sum()
    println("Sum of all values: $sum")

    // 5. Find the key of the maximum value in the dictionary.
    val maxEntry = dictionary.maxByOrNull { it.value }
    println("Key of maximum value: ${maxEntry?.key}")

    // 6. Create a new dictionary where the keys are the values and the values are the keys from the original dictionary.
    val reversedDictionary = dictionary.entries.associate { (key, value) -> value to key }
    println("Reversed Dictionary: $reversedDictionary")
}