Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

delete first element of dictionary python

#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
 
PREVIOUS NEXT
Tagged: #delete #element #dictionary #python
ADD COMMENT
Topic
Name
1+9 =