Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
659 B
1
Indexable
Never
def id_to_fruit(fruit_id: int, fruits: set[str]) -> str:
    idx = 0
    for fruit in fruits:
        if idx == fruit_id:
            print(idx, fruit_id, fruit)
            return fruit
        idx += 1
    raise RuntimeError(f"Fruit with id {fruit_id} does not exist")

print('{"apple", "orange", "melon", "kiwi", "strawberry"})')
fruits = {"apple", "orange", "melon", "kiwi", "strawberry"}
print(fruits)
name1 = id_to_fruit(1, {"apple", "orange", "melon", "kiwi", "strawberry"})
name3 = id_to_fruit(3, {"apple", "orange", "melon", "kiwi", "strawberry"})
name4 = id_to_fruit(4, {"apple", "orange", "melon", "kiwi", "strawberry"})

print(name1, name3, name4)