Detailed explanation of Python dictionary DICT type merging

巴扎黑
Release: 2017-08-18 13:29:52
Original
2113 people have browsed it

This article mainly introduces Python dictionary DICT type merging in detail, which has certain reference value. Interested friends can refer to it.

This article shares with everyone the Python dictionary DICT type merging method. Method, for your reference, the specific content is as follows

Some of the key values ​​​​of the dictionary I want are field names of the tables in the database, but some are not. I need to integrate them together, so some of them are in this article. (I have to make up 150 words, but I have no choice. Let’s talk about yesterday’s question. The session in python can only play a role in the requests library? You can’t save the value like in asp.net, and then set the expiration time. For verification? I originally wanted to find a library in python that has similar functions to the cache in asp.net. As a result, the python cache seems to be redis, memcached, mongodb, etc. There are one or two, but in the project It cannot be used in web.py. There is also a problem with using webpy's own session. Can't it be called across .py? Let's study it later)

Program example:


key = ['success', 'dangerous']
value = ''

# 返回的list
result_list = []
index = 0
while index < 4:
 # 中间字典,存储数据,以及防止append覆盖
 result_dict = {}
 _key = key[0]
 value = str(index)
 result_dict[_key] = value
 index = index + 1
 result_list.append(result_dict)
index = 0
return_list = []
print result_list
while index < 4:
 # 中间字典,存储数据,以及防止append覆盖
 result_dict = {}
 _key = key[1]
 value = str(index)
 result_dict[_key] = value
 dictMerge = dict(result_list[index].items() + result_dict.items())
 return_list.append(dictMerge)
 index = index + 1
print return_list
Copy after login

Program output:

Of course you can also play like this:


key = [&#39;success&#39;, &#39;dangerous&#39;]
value = &#39;&#39;

# 返回的list
result_list = []
index = 0
while index < 4:
 # 中间字典,存储数据,以及防止append覆盖
 result_dict = {}
 _key = key[0]
 value = str(index)
 result_dict[_key] = value
 index = index + 1
 result_list.append(result_dict)
index = 0
return_list = []
print result_list
while index < 4:
 # 中间字典,存储数据,以及防止append覆盖
 result_dict = {}
 _key = key[1]
 value = str(index)
 result_dict[_key] = value
 if int(result_list[index][&#39;success&#39;]) % 2 != 0:
  dictMerge = dict(result_list[index].items() + result_dict.items())
  result_list.remove(result_list[index])
  result_list.append(dictMerge)
 index = index + 1
print result_list
Copy after login

The above is the detailed content of Detailed explanation of Python dictionary DICT type merging. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!