recursion

Python: Loop through all nested key-value pairs created by xmltodict

穿精又带淫゛_ 提交于 2020-01-30 04:06:34
问题 Getting a specific value based on the layout of an xml-file is pretty straight forward. (See: StackOverflow) But when I don't know the xml-elements, I can't recurse over it. Since xmltodoc nests OrderedDicts in OrderedDicts. These nested OrderedDicts are typified by Python as type: 'unicode'. And not (still) as OrderedDicts. Therefor looping over like this, doens't work: def myprint(d): for k, v in d.iteritems(): if isinstance(v, list): myprint(v) else: print "Key :{0}, Value: {1}".format(k,

Python: Loop through all nested key-value pairs created by xmltodict

懵懂的女人 提交于 2020-01-30 04:05:10
问题 Getting a specific value based on the layout of an xml-file is pretty straight forward. (See: StackOverflow) But when I don't know the xml-elements, I can't recurse over it. Since xmltodoc nests OrderedDicts in OrderedDicts. These nested OrderedDicts are typified by Python as type: 'unicode'. And not (still) as OrderedDicts. Therefor looping over like this, doens't work: def myprint(d): for k, v in d.iteritems(): if isinstance(v, list): myprint(v) else: print "Key :{0}, Value: {1}".format(k,

Creating an array using recursive php from mysql

こ雲淡風輕ζ 提交于 2020-01-30 00:44:25
问题 I need to create an array from a mysql database organized like so id description parentId 1 Level 1 0 2 Level 2 0 3 Level 1a 1 4 Level 1b 1 5 Level 1a1 3 6 Level 1a1a 5 So that the output is like this: Level 1 Level 1a Level 1a1 Level 1a1a Level 1b Level 2 However my current code only outputs to the second level and then makes every other child it's own parent. Below is the current code: $query = "SELECT * FROM pB_test ORDER BY parentId ASC"; $result = mysql_query($query) or die ('Database

Creating an array using recursive php from mysql

人盡茶涼 提交于 2020-01-30 00:43:27
问题 I need to create an array from a mysql database organized like so id description parentId 1 Level 1 0 2 Level 2 0 3 Level 1a 1 4 Level 1b 1 5 Level 1a1 3 6 Level 1a1a 5 So that the output is like this: Level 1 Level 1a Level 1a1 Level 1a1a Level 1b Level 2 However my current code only outputs to the second level and then makes every other child it's own parent. Below is the current code: $query = "SELECT * FROM pB_test ORDER BY parentId ASC"; $result = mysql_query($query) or die ('Database

Php recursive function return null while variable have value

橙三吉。 提交于 2020-01-29 23:35:01
问题 This function returns NULL while $alias having value in second recursion. In first call it return the required value but when first if not matched and it recurse first the required value in avilable in $alias variable but it does not return anything. public function checkAlias($fname='',$lname=''){ if(!empty($fname)){ $fname = mysql_real_escape_string($fname); } if(!empty($lname)){ $lname = mysql_real_escape_string($lname); } $alias = strtolower($fname).strtolower($lname); $sql = "Select

Php recursive function return null while variable have value

我的未来我决定 提交于 2020-01-29 23:34:31
问题 This function returns NULL while $alias having value in second recursion. In first call it return the required value but when first if not matched and it recurse first the required value in avilable in $alias variable but it does not return anything. public function checkAlias($fname='',$lname=''){ if(!empty($fname)){ $fname = mysql_real_escape_string($fname); } if(!empty($lname)){ $lname = mysql_real_escape_string($lname); } $alias = strtolower($fname).strtolower($lname); $sql = "Select

R: split string into numeric and return the mean as a new column in a data frame

烂漫一生 提交于 2020-01-29 18:57:56
问题 I have a large data frame with columns that are a character string of numbers such as "1, 2, 3, 4". I wish to add a new column that is the average of these numbers. I have set up the following example: set.seed(2015) library(dplyr) a<-c("1, 2, 3, 4", "2, 4, 6, 8", "3, 6, 9, 12") df<-data.frame(a) df$a <- as.character(df$a) Now I can use strsplit to split the string and return the mean for a given row where the [[1]] specifies the first row. mean(as.numeric(strsplit((df$a), split=", ")[[1]]))

R: split string into numeric and return the mean as a new column in a data frame

陌路散爱 提交于 2020-01-29 18:57:25
问题 I have a large data frame with columns that are a character string of numbers such as "1, 2, 3, 4". I wish to add a new column that is the average of these numbers. I have set up the following example: set.seed(2015) library(dplyr) a<-c("1, 2, 3, 4", "2, 4, 6, 8", "3, 6, 9, 12") df<-data.frame(a) df$a <- as.character(df$a) Now I can use strsplit to split the string and return the mean for a given row where the [[1]] specifies the first row. mean(as.numeric(strsplit((df$a), split=", ")[[1]]))

How does PHP avoid infinite recursion here?

夙愿已清 提交于 2020-01-29 03:39:09
问题 Consider this class: class test { public function __set($n, $v) { echo "__set() called\n"; $this->other_set($n, $v, true); } public function other_set($name, $value) { echo "other_set() called\n"; $this->$name = $value; } public function t() { $this->t = true; } } I am overloading PHP's magic __set() method. Whenever I set a property in an object of the test class, it will call __set() , which in turn calls other_set() . $obj = new test; $test->prop = 10; /* prints the following */ __set()

Nice representation of primitive recursive functions in haskell

安稳与你 提交于 2020-01-28 09:56:08
问题 I argued in the answer to a previous question that it's possible to represent in Haskell the union of the primitive recursive functions (PRFs) and the single extra value of ⊥ or undefined . This argument was based on a direct translation of an axiomatic construction of primitive recursive functions; it required a number of language extensions and type-level reasoning about the arity of functions. Is it possible to represent an equivalent set of primitive recursive functions in more idiomatic