python - networkx and iteration of lists - piece of code I cannot understand -
i'm new python language , have been working networkx
package. have list of customers , producers , want function retrieves list of current list based on these types.
here relevant code function retrieves customers:
def customers_iter(self, data=false): """ return iterator on customers. if network changed during iteration, iterator becomes invalid. parameters ----------- data - if true, return list of (name, attributes) pairs, such attributes == net.node[name]. otherwise, list of customer names returned. default false. """ if data: return (n n in self.nodes_iter(data=true) if self.node[n[0]]["type"] == "customer") else: return (n n in self.nodes_iter() if self.node[n]["type"] == "customer")
my question regarding if- , else statement. point if first checking first node n[0]? doesn't statement in else-section define same thing?
regards, jazy
according doc comment:
data - if true, return list of (name, attributes) pairs, such attributes == net.node[name]. otherwise, list of customer names returned. default false.
assuming, data
parameter has same meaning in self.node_iter
function, first branch (if
) should filter pairs of (name, attributes)
, second 1 (else
) should filter name
s.
assuming, also, self.node
dictionary-like structure holding associative pairs name
-> node
, easy see, in first branch have retrieve name
tuple
(which n[0]
), while in second branch use n
node name.
Comments
Post a Comment