# Keys, values, or both — you choose.
# iterating over a dict — for, keys(), values(), items()

scores = {"Raven": 85, "Wolf": 74, "Ghost": 91}

# ─────────────────────────────────────────────
# Default loop — keys only
# ─────────────────────────────────────────────

for key in scores:
    print(key)

# Raven
# Wolf
# Ghost

# explicit — same result
for key in scores.keys():
    print(key)

# ─────────────────────────────────────────────
# Loop over values
# ─────────────────────────────────────────────

for value in scores.values():
    print(value)

# 85
# 74
# 91

# ─────────────────────────────────────────────
# Loop over key-value pairs — most common
# ─────────────────────────────────────────────

for name, score in scores.items():
    print(f"{name}: {score}")

# Raven: 85
# Wolf: 74
# Ghost: 91

# ─────────────────────────────────────────────
# Doing something with each pair
# ─────────────────────────────────────────────

for name, score in scores.items():
    if score >= 80:
        print(f"{name} — passed")

# Raven — passed
# Ghost — passed

# calculate total from loop
total = 0
for score in scores.values():
    total += score

print(f"Total: {total}")            # Total: 250
print(f"Average: {total / len(scores):.1f}")   # Average: 83.3

# ─────────────────────────────────────────────
# Building a new dict from a loop
# ─────────────────────────────────────────────

scores = {"Raven": 85, "Wolf": 74, "Ghost": 91, "Viper": 63}
passing = {}

for name, score in scores.items():
    if score >= 80:
        passing[name] = score

print(passing)      # {'Raven': 85, 'Ghost': 91}

# ─────────────────────────────────────────────
# Using the key inside the loop to update
# ─────────────────────────────────────────────

scores = {"Raven": 85, "Wolf": 74, "Ghost": 91}
bonus = 5

# don't modify while looping — build updated copy instead
updated = {}
for name, score in scores.items():
    updated[name] = score + bonus

print(updated)      # {'Raven': 90, 'Wolf': 79, 'Ghost': 96}

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# for key in d:               — loop over keys
# for key in d.keys():        — same, explicit
# for val in d.values():      — loop over values
# for k, v in d.items():      — loop over key-value pairs
#
# .items() is the most common pattern
# looping over a dict gives keys — not values or pairs
# don't modify a dict while looping over it
