How to create dictionary in Python?
(curly braces) {} creates a key-value pair with a colon (:) in the bracket and a single dictionary is created separately with a comma (,) for each pair. In addition, you can also create a dictionary with the dict () function. Let's look at some examples:
Try this code:
# empty dictionary
my_dict = {}# dictionary with integer keys
my_dict = {1: 'apple', 2: 'ball'}# dictionary with mixed keys
my_dict = {'name': 'Maruf', 1: [2, 4, 3]}# using dict()
my_dict = dict({1:'apple', 2:'ball'})# from sequence having each item as a pair
my_dict = dict([(1,'apple'), (2,'ball')])
Congratulations!
This post has been upvoted from Steemit Bangladesh, @steemitbd. It's the first steemit community project run by Bangladeshi steemians to empower youths from Bangladesh through STEEM blockchain. If you are from Bangladesh and looking for community support, Join Steemit Bangladesh Discord Server.
If you would like to delegate to the Steemit Bangladesh, you can do so by clicking on the following links:
50 SP, 100 SP, 250 SP, 500 SP, 1000 SP.
YOU ARE INVITED TO JOIN THE SERVER!