Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

dict.fromkeys with list as value

# vowels keys
keys = {'a', 'e', 'i', 'o', 'u' }
value = [1]

vowels = { key : list(value) for key in keys }
# you can also use { key : value[:] for key in keys }
print(vowels)

# updating the value
value.append(2)
print(vowels)

#Output
#{'a': [1], 'u': [1], 'o': [1], 'e': [1], 'i': [1]}
#{'a': [1], 'u': [1], 'o': [1], 'e': [1], 'i': [1]}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #list
ADD COMMENT
Topic
Name
7+4 =