Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python defaultdict

# Python program to demonstrate
# defaultdict
  
  
from collections import defaultdict
  
  
# Function to return a default
# values for keys that is not
# present
def def_value():
    return "Not Present"
      
# Defining the dict
d = defaultdict(def_value)
d["a"] = 1
d["b"] = 2
  
print(d["a"]) # 1
print(d["b"]) # 2
print(d["c"]) # Not Present
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #defaultdict
ADD COMMENT
Topic
Name
4+8 =