#Author:  James Tam
#Version: October 22, 2024


#Create dictionary
scientists = {}
i = 1
size = 4
#New dictonary operation #3: Create dictionary dynamically via a loop
while(i <= size):
    scientists[i] = "Scientist #" + str(i)
    i = i + 1
#Traverse original dictionary
i = 1
for scientist in scientists:
    print("\tID:%d, Name: %s" %(scientist,scientists[i]))
    i = i + 1

size = size + 1
#New dictonary operation #1: Create new new element
scientists[size] = "Scientist #" + str(size)

#New dictonary operation #2: Modify existing element (key=2)
scientists[2] = "James Tam"

#New dictonary operation #4: Deleting element by key
del scientists[1]

#Traverse updated dictionary
i = 2  #Element with key=1 has been deleted
print("-")
for scientist in scientists:
    print("\tID:%d, Name: %s" %(scientist,scientists[i]))
    i = i + 1
print("-")



#New dictionary operation #5: Checking for membership
key = 1
if key in scientists: #check if that scientist exists, lookup via key
    print("Scientist with ID %d exists" %(key))
else:
    print("No such scientist with ID %d" %(key))
key = 2
if key in scientists:
    print("Scientist with ID %d exists" %(key))
else:
    print("No such scientist with ID %d" %(key))
input("press enter") 

#New dictionary operation #6: Clearing the whole dictionary
scientists.clear()
size = len(scientists)
print("size", size)
print("Displaying cleared dictionary")
for scientist in scientists:
    print(scientist)


