SetDefault () methodParameters
Key--The value of the lookup.
Default-key is not present, set the defaults.
GrammarSetDefault () method syntax:Dict. SetDefault(key,default=None) DescriptionIf the parameter key does not exist in the dictionary, the key is added and the value of the key is set to default.If the parameter key already exists, do not take any actionreturn valueThe method does not have any return value.InstanceWhen
Summary of several methods to traverse the python Dictionary (recommended) and python dictionary
As follows:
ADict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} print '----------- dict -----------' for d in aDict: print "% s: % s" % (d, aDict [d]) print '----------- item -----------' for (k, v) in aDict. items (): print '% s: % s' % (k, v) # The most efficient print' ------------ iteritems ------
PHP can obtain and generate a database dictionary. php can obtain a database dictionary.
This example describes how PHP can obtain and generate a database dictionary. We will share this with you for your reference. The details are as follows:
Welcome to follow Me blog: Cloud DreamerDescriptionThe Python Dictionary items () method returns a traversal (key, value) array of tuples in a list form (not a direct list, to return a list value and also call the list function).GrammarDict.items()Parameters
NA
return valueReturns an array of traversed (key, value) tuples as a list.ExampleExample code:= {‘Google‘‘www.google.com‘‘Runoob‘‘www.runoob.com‘‘taobao‘‘www.taobao.com‘}print("字典值
Dictionary traversal is the traversal of key, and the order of key selection is unordered:def print_hist (h): For C in H:print C, H[c]Dict reverse lookup and throws an exception:def reverse_lookup (d, v): for K in d:if d[k] = = V:return k raise ValueError, ' element not found 'Initialize Dict:ENG2SP = {' One ': ' Uno ', ' both ': ' dos ', ' three ': ' Tres '}Dict lengthLen (ENG2SP)In operator to determine if a specific key is included>>> ' one ' in en
First, generate a random dictionary:From random import RandintD={x:randint (60,99) for x in "ABCDEFG"} # {' A ': +, ' B ': $, ' C ': "All, ' d ':", ' e ': ", ' F ': $, ' G ': 88}In the first way, the subclasses of collections are sorted from large to small counter:From collections Import CounterD={x:randint (60,99) for x in "ABCDEFG"}C=counter (d). Most_common () #返回一个列表, in accordance with the value of dict from large to small sort [(' B ', '), (' G ', "), (' d ',"), (' E ', "), (' A '," five
according to the level of performance, calculate ranking 1. Convert dictionary data into tuples using zip
From random import randint
d = {x:randint (MB) for x in ' abcdef '}
print D
print sorted (d)
print zip (d . Itervalues (), D.iterkeys ())
print sorted (Zip (d.itervalues (), D.iterkeys ())
2. Pass the key parameter of the sorted function
"" "
Key=lambda x:x[1]
passes one of the items in to X, defines which part is used as the value of the com
Source code of the Application Project of the imitation youdao dictionary and the source code of the youdao dictionary Project
I mainly learn how to automatically switch viewPage with threads, apply iflytek voice, Baidu translation API, pull-up and load pull-down refresh. The combination of listView and ScrollView does not conflict. Please forgive me if you haven't done it yet.
Download source code:Http
Python-Level 7 dictionary query and python dictionary Query
1 #-*-coding: UTF-8-*-2 3 4 # job requirements: 5 # five menus of municipalities, provinces, municipalities, counties, districts, and sub-streets; 6 # Step by step to all layers 7 # exit to the previous Layer 8 # exit program at any time 9 10 11 mapChina = {12 "People's Republic of China": {13 "Beijing ": {14 "city": {15 "Dongcheng District" :{}, 1
Dictionary Case demonstration and dictionary Case demonstration
Case: 10 students are added by name. There are three tests for Chinese, mathematics and English. The scores are randomly generated for these 10 students [50]
Requirement: print a score table.
The data storage format is as follows:
ImportRandom
#Initialize basic student information
Dic_student_info = {95001:"Wang Yi", 95002:"Hu 'er", 95003:"Zhan
Sort the dictionary
Like student grades.{' Lilei ': Hanmeimei, ' Wang ': ",": 90}Calculate ranking based on student scores preferred sorted () function or Sort method The first method: using Zip to convert a dictionary into a tuple
D = {K:randint (60,100) for K in (' abcxyz ')}
#{' A ':, ' C ': M, ' B ':, ' y ': ", ' X ':", "Z":
#当字典很大时d. itervalues () is smaller than the direct use of the d.values () ov
1. Sort by dictionary value
student_1={
' A ': 2,
' B ': 4,
' C ': 6,
' d ': 8
}
student_1_sort = sorted (Student_1.iteritems (), Key=lambda d:d[1], reverse=true)
print (Student_1_sort)
Output:
[(' d ', 8), (' C ', 6), (' B ', 4), (' A ', 2)]
2. Sort by value of a key in the dictionary in list
Student_2 = [
{
"no": 1,
"score": +
},
{
"no": 2,
Compare two dictionaries output all additions to delete modifications by dictionary if there is no update output no changes
Map Application Comparison Two dictionaries note that the processing of the starting string and the dictionary can be empty
Import Java.math.BigInteger;
Import java.util.Collections;
Import Java.util.HashMap;
Import Java.util.Iterator;
Import Java.util.Map;
Import Java.util.Scanner;
1. Object definition
When the Create command is executed to create an object, Oracle stores the object definition in the data dictionary.
03:31:40 sql> Select Dbms_metadata.get_ddl (' TABLE ', ' DEPT ') DDL from DUAL;
Ddl
--------------------------------------------------------------------------------
CREATE TABLE "SCOTT". " DEPT "
("DEPTNO" number (2,0),
"Dname" VARCHAR2 (14
2, viewing the space occupied by the object
03:36:48 sql> Conn Scot
end of a straight line, requiring different stick to the side must be the same color.
Seems to be judging the Euler loop.
From the knowledge of graph theory, the necessary and sufficient conditions for the existence of Euler paths in the direction-free graphs are:
the ① graph is connected;
② all nodes have an even number of degrees, or a node with an odd number of two degrees.
the connection of graphs can be judged by using and searching the set.
the statistics of degrees are easier.
The dat
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.