Interpreting python segment -


I'm new to Python and came into this section of code. Can anyone help me with syntax here? Maybe give some comments on each line how it is working? xs is a list that includes dates.

  for data = {}, tmpdata.items () in d: data [title] = [x and d [x] [statid] in x or x for x] Data [Title] [- 1] = Max [statid]    

If I think , Then I would say that someone should be the most complicated line for the dragon:

  data [title] = [xd and d [x] [statid] or x for x X]   

There's a lot going on here, and some of it uses a style, though in this example Secure, now is not recommended here is a more active form: x [x] in x [data] = []: if x in d and d [x] [ Statid]: data [title] .append (d [x] [statid]) Other: data [title] .append (0)

build position and value-if- The situation is true or value-if-condition is false SeaTrontary form is an old style form of condition? Value-if-status is true: value-if-condition-is-false . The given Python expression hides a secret bug which is evaluated as a value of value-if-condition-true-true by Python as "incorrect-y" value - 0, [ ], () are all values ​​that are considered false when used in conditional expression, so if your value-if-condition-true-qualified has been excluded, then You may have problems, be one of them. As in this case, if d [x] [statid] is 0, then we will consider one wrong result and will go ahead and add 0 to the list, whatever will be the right thing as well. If we can only edit the verbose form, then the simplest and d [x] [statid] must be removed from the following:

  data [title] = [X] For X in X: D in the data: [title] .append (d [x] [statid]) Other: data [title] .append (0)   

Or use the new Python Ternary Form (which gives a grain to some people, but I have become accustomed to doing this - Ternary Form, not Dras), which is written as:

 < Code> value-if-c Ondition   

or replacement in our verbose form:

  data [title] = [] x for x: data [title] .append (d [ X] [statid] if x in d else 0)   

So in the end, understand the list part. Whenever you have such a loop:

  listvar = [] for some moving-state: listvar.append (some moving-dependent values)   < P> You can rewrite it:  
  listvar = [some walking-dependency for some moving-dependency-value]   

and this form Calling a list called it creates a list by following the state of repetition and evaluating the value for each walk.

So you can now see how the original description will be written. Due to the possible hidden bug in the old-style position and true-value or false-value , the form of a threesome or a clear if-then-second is now the preferred style code should be written today:

  data [title] = [d [x] [statid] if x in x for x and x in x]] ​​   

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -