xxxxxxxxxx
#Heres on INEFFICIENT way to do it:
dictionary = {'first': 0, 'second': 1, 'thrid': 2}
#THIS METHOD IS FOR THE SITUATION WHERE YOU DONT KNOW WHAT THE FIRST KEY IS CALLED!!!
list = [[item, dictionary[item]] for item in dictionary]
list.pop(0)
new_dictionary = {}
for item in list:
if item[0] not in new_dictionary:
dictionary[item[0]] = item[1]
#Hope this works
xxxxxxxxxx
(k := next(iter(d)), d.pop(k))
which will return and remove the leftmost (first) item if it exists
xxxxxxxxxx
a_dict = {
'site': 'bobbyhadz.com',
'topic': 'Python',
'id': 100
}
first_key = next(iter(a_dict))
print(first_key) # site
first_value = a_dict.pop(first_key)
print(first_value) # bobbyhadz.com
print(a_dict) # {'topic': 'Python', 'id': 100}