nested

How to create a tree (parent-child) object from Array in Javascript

余生长醉 提交于 2020-01-11 12:21:09
问题 I have an array like [ "parent1|child1|subChild1", "parent1|child1|subChild2", "parent|child2|subChild1", "parent1|child2|subChild2", "parent2|child1|subChild1", "parent2|child1|subChild2", "parent2|child2|subChild1", . . . ] Wherein my first string before | is the parent and the second string before | is the child and the third string after the second | is the subchild How can I convert this array into an object like [ { "id": "parent1", "children":[ { "id": "child1", "children":[ { "id":

How do I map multiple lists with dapper

不想你离开。 提交于 2020-01-11 11:45:46
问题 I've got three classes User, Order & Project which are stored in single tables. The orders and projects both have a n:n relation with the users. To implement that I've got two crosstables (UserOrders, UserProjects) which map these relations. public class User { public string UserID {get;set;} public List<string> Orders{get;set;} public List<string> Projects {get;set;} } public class Order { public string OrderID {get;set} ... } public class Project { public string ProjectID {get;set} ... } As

How do I map multiple lists with dapper

て烟熏妆下的殇ゞ 提交于 2020-01-11 11:45:10
问题 I've got three classes User, Order & Project which are stored in single tables. The orders and projects both have a n:n relation with the users. To implement that I've got two crosstables (UserOrders, UserProjects) which map these relations. public class User { public string UserID {get;set;} public List<string> Orders{get;set;} public List<string> Projects {get;set;} } public class Order { public string OrderID {get;set} ... } public class Project { public string ProjectID {get;set} ... } As

Create a pandas dataframe from a nested lists of unequal lengths

眉间皱痕 提交于 2020-01-11 09:16:46
问题 So I have a list as follows: aa = ['aa1', 'aa2', 'aa3', 'aa4', 'aa5'] bb = ['bb1', 'bb2', 'bb3', 'bb4'] cc = ['cc1', 'cc2', 'cc3'] Which is then created into a nested list: nest = [aa, bb, cc] I want to create a dataframe as follows: aa bb cc aa1 bb1 cc1 aa2 bb2 cc2 aa3 bb3 cc3 aa4 bb4 nan aa5 nan nan I've tried: pd.DataFrame(nest, columns=['aa', 'bb', cc']) But results is such that, each list is being written as a row (as opposed to a column) 回答1: The zip_longest function from itertools does

Create a pandas dataframe from a nested lists of unequal lengths

怎甘沉沦 提交于 2020-01-11 09:14:57
问题 So I have a list as follows: aa = ['aa1', 'aa2', 'aa3', 'aa4', 'aa5'] bb = ['bb1', 'bb2', 'bb3', 'bb4'] cc = ['cc1', 'cc2', 'cc3'] Which is then created into a nested list: nest = [aa, bb, cc] I want to create a dataframe as follows: aa bb cc aa1 bb1 cc1 aa2 bb2 cc2 aa3 bb3 cc3 aa4 bb4 nan aa5 nan nan I've tried: pd.DataFrame(nest, columns=['aa', 'bb', cc']) But results is such that, each list is being written as a row (as opposed to a column) 回答1: The zip_longest function from itertools does

Building Nested dictionary in Python reading in line by line from file

青春壹個敷衍的年華 提交于 2020-01-11 07:35:15
问题 The way I go about nested dictionary is this: dicty = dict() tmp = dict() tmp["a"] = 1 tmp["b"] = 2 dicty["A"] = tmp dicty == {"A" : {"a" : 1, "b" : 1}} The problem starts when I try to implement this on a big file, reading in line by line. This is printing the content per line in a list: ['proA', 'macbook', '0.666667'] ['proA', 'smart', '0.666667'] ['proA', 'ssd', '0.666667'] ['FrontPage', 'frontpage', '0.710145'] ['FrontPage', 'troubleshooting', '0.971014'] I would like to end up with a

Extract values by key from a nested dictionary

天涯浪子 提交于 2020-01-11 06:59:52
问题 Given this nested dictionary, how could I print all the "phone" values using a for loop? people = { 'Alice': { 'phone': '2341', 'addr': '87 Eastlake Court' }, 'Beth': { 'phone': '9102', 'addr': '563 Hartford Drive' }, 'Randy': { 'phone': '4563', 'addr': '93 SW 43rd' } 回答1: for d in people.values(): print d['phone'] 回答2: Loop over the values and then use get() method, if you want to handle the missing keys, or a simple indexing to access the nested values. Also, for the sake of optimization

jQuery hover event with nested elements

倾然丶 夕夏残阳落幕 提交于 2020-01-10 05:34:26
问题 I've currently got your basic, run-of-the-mill menu tree as follows: <ul id="nav"> <li> <a href="#">home</a> <div class="controls">Some controls go here</div> <ul> <li> <a href="#">item 1</a> <div class="controls">Some controls go here</div> </li> <li> <a href="#">item 2</a> <div class="controls">Some controls go here</div> </li> </ul> </li> </ul> The divs with the "controls" class are hidden to start with. What I want to happen is that when you hover over an li, the controls for that

how to define dynamic nested loop python function

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 02:43:08
问题 a = [1] b = [2,3] c = [4,5,6] d = [a,b,c] for x0 in d[0]: for x1 in d[1]: for x2 in d[2]: print(x0,x1,x2) Result: 1 2 4 1 2 5 1 2 6 1 3 4 1 3 5 1 3 6 Perfect, now my question is how to define this to function, considering ofcourse there could be more lists with values. The idea is to get function, which would dynamicaly produce same result. Is there a way to explain to python: "do 8 nested loops for example"? 回答1: You can use itertools to calculate the products for you and can use the *

How to find all IDs of children recursively?

陌路散爱 提交于 2020-01-09 06:56:26
问题 I would like to get all IDs from children in a tree with MySQL only. I have a table like this: ID parent_id name 1 0 cat1 2 1 subcat1 3 2 sub-subcat1 4 2 sub-subcat2 5 0 cat2 Now I'm trying to get all child IDs for cat1 (2,3,4) recursively. Is there any way how to achieve that? 回答1: There are two basic methods for doing this: adjacency lists and nested lists. Take a look at Managing Hierarchical Data in MySQL. What you have is an adjacency list. No there isn't a way of recursively grabbing