Copyright © tutorialspoint.com
This method creates a new dictionary with keys from seq and values set to value.
dict.fromkeys(seq[, value])) |
Here is the detail of parameters:
seq: This is the list of values which would be used for dictionary keys preparation.
value: This is option, if provided then value would be set to this value.
#!/usr/bin/python seq = ('name', 'age', 'sex') dict = dict.fromkeys(seq) print "New Dictinary : %s" % str(dict) dict = dict.fromkeys(seq, 10) print "New Dictinary : %s" % str(dict) |
This produces following result:
New Dictinary : {'age': None, 'name': None, 'sex': None} New Dictinary : {'age': 10, 'name': 10, 'sex': 10} |
Copyright © tutorialspoint.com