“Dikt Python Hapus Kunci” Kode Jawaban

Hapus kunci dari Dict Python

''' 
Deleting an entry from dictionary using del 
'''
# If key exist in dictionary then delete it using del.
if "at" in wordFreqDic:
    del wordFreqDic["at"]
    
print("Updated Dictionary :" , wordFreqDic)      
Arrogant Anaconda

Dikt Python Hapus Kunci

my_dict.pop('key', None)
Fair Ferret

Hapus kunci dari kamus

if 'key' in my_dict:
    del my_dict['key']
Real Raccoon

Hapus elemen dari Kamus Python

squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

# remove a particular item, returns its value
# Output: 16
print(squares.pop(4))
Yucky Yacare

Kunci Hapus Dikt Python

# Python code to demonstrate
# removal of dict. pair 
# using del
  
# Initializing dictionary
test_dict = {"Arushi" : 22, "Anuradha" : 21, "Mani" : 21, "Haritha" : 21}
  
# Printing dictionary before removal
print ("The dictionary before performing remove is : " + str(test_dict))
  
# Using del to remove a dict
# removes Mani
del test_dict['Mani']
  
# Printing dictionary after removal
print ("The dictionary after remove is : " + str(test_dict))
  
# Using del to remove a dict
# raises exception
del test_dict['Manjeet']
Elegant Eland

Hapus kunci dari Kamus Python

del my_dict['key']
Computer Expert

Jawaban yang mirip dengan “Dikt Python Hapus Kunci”

Pertanyaan yang mirip dengan “Dikt Python Hapus Kunci”

Lebih banyak jawaban terkait untuk “Dikt Python Hapus Kunci” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya