Search
 
SCRIPT & CODE EXAMPLE
 

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]}
Comment

PREVIOUS NEXT
Code Example
Python :: show all columns pandas jupyter notebook 
Python :: generic type python 
Python :: How can I install XGBoost package in python on Windows 
Python :: convert pandas column type 
Python :: python from timestamp to string 
Python :: how to print a string by reverse way in python 
Python :: sneaker bots 
Python :: pathlib path get directory of current file 
Python :: install from github 
Python :: python read line into list 
Python :: generate sha1 python 
Python :: show image python 
Python :: jupyter lab 
Python :: python match phone number 
Python :: pandas reorder columns by name 
Python :: sort list of numbers python 
Python :: replace newline character in python 
Python :: dataframe choose random 
Python :: add text to pygame window 
Python :: find order of characters python 
Python :: check if string has digits python 
Python :: add column in a specific position pandas 
Python :: seaborn correlation 
Python :: how to read text frome another file pythion 
Python :: print output python to file 
Python :: Python make directories recursively 
Python :: django file upload this field is required 
Python :: converting binary to octal in python 
Python :: sorting numbers in python without sort function 
Python :: pre commit python 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =