Answers for "fromkeys in python"

2

dictionary function fromkeys in python

key = { "India", "Austria", "USA", "Pakistan", "Czech Republic"}
value  = "Country"
countries = dict.fromkeys(key, value) # function fromkeys
counties
#returns {'USA': 'Country',
 'Pakistan': 'Country',
 'Austria': 'Country',
 'India': 'Country',
 'Czech Republic': 'Country'}
Posted by: Guest on December-10-2020
1

fromkeys() in python

x = ('key1', 'key2', 'key3')
y = 0

thisdict = dict.fromkeys(x, y)

    
print(thisdict)

//Output:{'key1': 0, 'key2': 0, 'key3': 0}
Posted by: Guest on May-21-2021
2

fromkeys in python

sequence1={1,2,3}
sequence2={"a","b","c"}
values1="Numbers"
values2="Alphabets"
dict1.fromkeys(sequence1,values1)
#returns {1: 'Numbers', 2: 'Numbers', 3: 'Numbers'}

dict2.fromkeys(sequence2,values2)
#returns {'c': 'Alphabets', 'b': 'Alphabets', 'a': 'Alphabets'}
Posted by: Guest on September-18-2020
0

dict.fromkeys in python

for fruit, color in test.items():
    # do stuff
Posted by: Guest on May-04-2020

Python Answers by Framework

Browse Popular Code Answers by Language