Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create a dictionary from a list python

fruits = ["Apple", "Pear"]

# Create a dictionary using as keys the values in fruits list
fruit_dictionary = dict.fromkeys(fruits, "In Stock")
print(fruit_dictionary)  # {'Apple': 'In Stock', 'Pear': 'In Stock'}

# Alternatively, dictionary comprehension can be used for same purpose
fruit_dictionary = { fruit : "In stock" for fruit in fruits }
print(fruit_dictionary)  # {'Apple': 'In Stock', 'Pear': 'In Stock'}
Comment

creating a dictionary from lists

a = [10,20,30]
b = [100,200,300]
my_dictionary = dict(a=a, b=b)
Comment

PREVIOUS NEXT
Code Example
Python :: email confirmation django 
Python :: py list 3d 
Python :: Python Sort Lists 
Python :: python remove vowels from string 
Python :: pd.loc 
Python :: django set cookie 
Python :: import python code from another directory 
Python :: conditional subsetting python 
Python :: show only integer values matplotlib 
Python :: path selecter in tkinter 
Python :: sns prevent legend 
Python :: int to byte array python 
Python :: how to append to an empty dataframe pandas 
Python :: UserWarning: Failed to initialize NumPy: numpy.core.multiarray failed to import (Triggered internally at 
Python :: Getting the string and the regex of the matched object 
Python :: how to set date and time rows in order python pandas 
Python :: Python __add__ magic method 
Python :: NumPy fliplr Syntax 
Python :: create a list of sequential numbers in python 
Python :: format binary string python 
Python :: better way to see full csv in jupyter notebook 
Python :: Dictionary get both key and value. 
Python :: python find cells with na 
Python :: python kubernetes client find pod with name 
Python :: decision tree 
Python :: calculate the surface area of a cylinder python 
Python :: how to import ui file in pyside 
Python :: pipeline model coefficients 
Python :: Merge 2 or more notebooks into one 
Python :: check if element is in list 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =