in the Python function, enter the keyword parameter--the dictionary parameter, how to output in the order of input.
For ease of understanding, cite several examples: example one:
https://www.zhihu.com/question/24360507
#编写者
def Test (**kwargs):
print Args.keys ()
#使用者, I call
Test (a=1, c=3, d=2, e=4) as
follows The OUTPUT keyword is then given to the output (a,c,d,e) in the order of the function call, rather than the unordered output.
Example Two:
From the user's point of view, such as the reduced use of functions most humane and clear
In (id=4,name= ' ding ')
in (iq=100,eq=90)
in (code= ' good ', date=16)
From the writer's point of view, the parameter name is variable, the parameter value is variable, the number of parameters is variable, it is obvious to adopt **kwargs--keyword parameters, more reasonable. Workaround:
#目标: Test (id=4,name= ' ding ')
#从数学角度上分析, estimating the number of times the user presses the keyboard: 17
1. Using the advice of netizens, enter the order of additional.
Test (id=4,name= ' Ding ', order_list= (' id ', ' name '))
Obviously, this is very impersonal, for the user's angle is particularly unreasonable, not suitable for product needs.
From the point of view of mathematics, the number of users who use the keyboard is estimated as: 32
Wrong. 2. Change the way of thinking, change to use variable parameter input, so you can output in the order of input
Test (' ID ', 4, ' name ', ' Ding ')
It is easier to see than the first method.
From the user's point of view, the trouble lies in the need to split the input parameters, even when the number of parameters, the operand geometry explosion.
From the writer's point of view, the trouble is to identify the types of parameters, more complex.
From the point of view of mathematics, the number of users who use the keyboard is estimated as: 19
Not good. 3. In order to not meet the requirements of sequential output, the use of variable parameter input
def test (**kwargs)
But the variable parameters are unordered dictionaries, if you want to sequentially output, after consulting a large number of data, determine the contradictions between the two, can not reconcile ...
My idea now is to see if I can change the mechanism in Python--the interpreter. If the vast numbers of users Daniel, have the idea of a solution, welcomed the following comments or private chat ...
Can ' t be achieved Or Very Hard. 4. The most perfect approach
#编写者
def Test (string):
#伪代码
orderdict=orderdict (String.Replace (', ', ' = ')
#使用者:
Test ("id=4, Name= ' ding ' ")
If the reader is personally tested, it will be found that no matter
From the writer's point of view, the difficulty and complexity of writing decreased.
From the user's point of view, there is one More button ""
From the point of view of mathematics, the number of users who use the keyboard is estimated as: 18
Much good.
Finally, if you feel useful or have an idea, welcome to the point of praise or comment.
python group: 190341254
Ding.