how to add data into dictionary in python

how to add data into dictionary in python

Hi,

I have a python API that returns Python dictionary. It contains many values. Here is simple example of my dictonary:

clientDict = {"name":"John", "address":"Singapore", "age":35}

I want to add DOB to this dictionary object. how to add data into dictionary in python?

Thanks

View Answers

July 18, 2021 at 6:50 PM

Hi,

Its very easy to add new values in Python dictionary. Here is code for adding the dob in the existing dictionary:

clientDict = {"name":"John", "address":"Singapore", "age":35}

clientDict[""] ="2005-02-06"

print(clientDict)

If you run the program you will find the dob is added to the dictionary:

>>> clientDict = {"name":"John", "address":"Singapore", "age":35}
>>> 
>>> clientDict[""] ="2005-02-06"
>>> 
>>> print(clientDict)
{'name': 'John', 'address': 'Singapore', 'age': 35, '': '2005-02-06'}
>>>

Thanks


July 18, 2021 at 6:51 PM

Hi,

Check more tutorials at:

Thanks


July 18, 2021 at 6:56 PM

Hi,

Here is updated code:

clientDict = {"name":"John", "address":"Singapore", "age":35}

clientDict["dob"] ="2005-02-06"

print(clientDict)

Thanks

Ads









Related Tutorials/Questions & Answers:
how to add data into dictionary in python
how to add data into dictionary in python  Hi, I have a python API that returns Python dictionary. It contains many values. Here is simple example...} I want to add DOB to this dictionary object. how to add data into dictionary
How to add a new item to a dictionary in Python
How to add a new item to a dictionary in Python  Hi, I have an existing dictionary in Python. I want to add new item to it. How to add a new item to a dictionary in Python? Thanks   Hi, Python dictionary is very
Advertisements
Add a new item to a dictionary in Python
Add a new item to a dictionary in Python  Hi, I have an dictionary in Python and I want to add new item to it. What is the best way to add an item to a python dictionary? Share me example for adding a new item to a dictionary
How to append a dictionary to a list in Python
is to add the dictionary into the list. How I can achieve this? How to append a dictionary to a list in Python? Thanks   Hi, Here is the simple example...How to append a dictionary to a list in Python  Hi, I have a loop
how to access python dictionary elements
how to access python dictionary elements  Hi, I am new to Python... dictionary object. What is code for accessing elements from Python dictionary? How to access python dictionary elements? Thanks   Hello, Python
how to access python dictionary elements
how to access python dictionary elements  Hi, I am new to Python... dictionary object. What is code for accessing elements from Python dictionary? How to access python dictionary elements? Thanks   Hello, Python
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data...:"Seven", 8:"Eight", 9:"Nine", 10:"Ten"} print(word_dict) How to get all keys
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data...:"Seven", 8:"Eight", 9:"Nine", 10:"Ten"} print(word_dict) How to get all keys
how to add dynamic data
how to add dynamic data  how to add dynamic data to an existing web application
How to convert Python dictionary to JSON?
How to convert Python dictionary to JSON? Python example to create dictionary... with the JSON data format. In this example I will show you how to instantiate Python... Convert dictionary to JSON Python Python variables and data
How do I convert a dictionary to a JSON object in Python?
How do I convert a dictionary to a JSON object in Python?  Hi, I have a project where we are getting the data from one source and the API used is returning the dictionary object. Now our requirement is to convert it to JSON
Python Dictionary
in Python. Let's get started with the Python Dictionary data structure. What is Python Dictionary? Dictionary is one of the data structure in Python which... will see how to create a dictionary object in Python. In Python dictionary object
python sorted dictionary
python sorted dictionary  Hi, Is it possible to sort the dictionary in Python. I am trying to find examples of sorted dictionary in Python. Thanks
two list to dictionary python
two list to dictionary python  Hi, I have two lists and I want to covert it into dictionary. I want to create keys from one list and values from another list. How I can convert two list to dictionary python? Thanks   
How to append dictionary to a list in loop
How to append dictionary to a list in loop  Hi, I have to write a program in Python for appending dictionary to list in for loop. I will be creating... to achieve this? How to append dictionary to a list in loop? Thanks  
Read JSON file into Python dictionary
How to Read JSON file into Python dictionary? This is quick guide..." } Following program is used read the data into Python dictionary...; In this tutorial we learned to read json file data into dictionary object in Python
Read JSON file into Python dictionary
How to Read JSON file into Python dictionary? This is quick guide..." } Following program is used read the data into Python dictionary...; In this tutorial we learned to read json file data into dictionary object in Python
Convert dictionary to JSON Python
Converting dictionary object to JSON in Python program Dictionary is one of the most used data structure in Python. It allows you to store values... library. Consider the following dictionary: book_dict = {"name":"Python Book
Convert dictionary to JSON Python
Converting dictionary object to JSON in Python program Dictionary is one of the most used data structure in Python. It allows you to store values... library. Consider the following dictionary: book_dict = {"name":"Python Book
Python sum dictionary values by key
Python sum dictionary values by key  Hi, In python we can easily create dictionary and store the values in it. In dictionary we store the values.... What is the code for Python sum dictionary values by key? Thanks
ModuleNotFoundError: No module named 'NHANES-semantic-data-dictionary-annotation'
-semantic-data-dictionary-annotation python with following command: pip install...-semantic-data-dictionary-annotation python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'NHANES-semantic-data-dictionary
ModuleNotFoundError: No module named 'plover-python-dictionary'
: No module named 'plover-python-dictionary' How to remove the ModuleNotFoundError: No module named 'plover-python-dictionary' error? Thanks  ...ModuleNotFoundError: No module named 'plover-python-dictionary'  Hi
ModuleNotFoundError: No module named 'plover-python-dictionary'
: No module named 'plover-python-dictionary' How to remove the ModuleNotFoundError: No module named 'plover-python-dictionary' error? Thanks  ...ModuleNotFoundError: No module named 'plover-python-dictionary'  Hi
how to read from dictionary c
how to read from dictionary c  how to read elements from dictionary in c programming
adding one element in dictionary python
adding one element in dictionary python  Hi, I am looking for code for adding one element in dictionary python. Thanks   Hi, Here is sample code: dict ={"name":"Rose India"} print(dict) #add one more element dict
How do you sum a dictionary
How do you sum a dictionary  Hi, I want to sum the values of two dictionary based on keys. How do you sum a dictionary
How is Python used for data science?
How is Python used for data science?  Hi, I am beginner in Data...: How is Python used for data science? Try to provide me good examples or tutorials links so that I can learn the topic "How is Python used for data science
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp  hi friends i am doing a project in jsp and oracle as my database.In my project i have an registration form containing many text fields.there is no problem
How to add
How to add   Hi, I want to make a website which will recommend users books according to the genre selected by them. I am using PHP, JavaScript and mySQL. The problem is that there will me almost more than 100 books
how to write a english dictionary project in java
how to write a english dictionary project in java  please give me idea how to write program/source code for dictionary project
How do you combine two dictionary values for common keys
be:: final = {"a":500, "b":500, "c":1300} How to combine values in a new dictionary? I want example code in Python. How do you combine two dictionary values...How do you combine two dictionary values for common keys  Hi, I have

Ads