Merge operation of how python dictionary
This article mainly shows you "python how to merge dictionaries", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "python how to merge dictionaries" this article bar.
dictionary merge operation
For example, if we have two dictionaries that store user names and passwords for different users, we can write a program to merge the two dictionaries:
a = {"ross":"123456","xiaoming":"xiao123"} b = {"lili":"11111","nana":"123456"} c = {} for k in a : c[k] = a[k] for k in b: c[k] = b[k]
We can rewrite the program as follows:
a = {"ross":"123456","xiaoming":"xiao123"} b = {"lili":"11111","nana":"123456"} c = {**a, **b}
The two ** signs are called unpacking in python, which means that the contents of a and b are directly put into c.
The above is "python how dictionary merge operation" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!