nested-lists

How to sort nested lists into seperate lists with unique values in python?

a 夏天 提交于 2019-12-02 05:06:47
I have two variables: unique_val = [1,2,3] nested_list = [['name1',1],['name2',1],['name3',3],['name4',2],['name5',2],['name6',3]] Basically I want separate lists of the names at each unique value. I struggled to put together a set of nested for loops to no avail. Ideally the output would be something like this: list_1 = ['name1','name2'] list_2 = ['name4','name5'] list_3 = ['name3',name6'] Creating variables for each item in unique_val is not a good idea. Instead of hard coding everything better use a dict with keys like list_1 as it'll handle any number number of variables. >>> from

How to group set of data.frame objects in nested list with different order?

我的未来我决定 提交于 2019-12-02 04:10:52
I have set of data.frame object in nested list, I want to group them by name of data.frame object. Because each nested list, data.frame objects are placed in different order, I have difficulty to group them in new list. I tried transpose method from purr packages in CRAN, but it wasn't right answer that I expected. Does anyone knows any trick of doing this sort of grouping for data.frame object more efficiently? Thanks a lot example: res_1 <- list(con=list(a.con_1=airquality[1:4,], b.con_1=iris[2:5,], c.con_1=ChickWeight[3:7,]), dis=list(a.dis_1=airquality[5:7,], b.dis_1=iris[8:11,], c.dis_1

Excel vba nested dictionary - accessing items

不问归期 提交于 2019-12-01 17:57:19
Tim is it possible to extract a list of row keys from the clsMatrix class? something like this... Sub KEYS() Dim KEY_LIST As Variant KEY_LIST = TABLES("UDLY").dR.KEYS End Sub I can then cycle through a table to extract a subset of data which meet a certain criteria. Tim, your code works well for one 2D matrix, but I have 5 tables to reference for the project to work. I tried using if...then else statements, but it's clumsy and doesn't work - the second pass looking for data from the BOOK table can't find the row and col dictionary references. Can you suggest a better method? Thanks for your

Excel vba nested dictionary - accessing items

南笙酒味 提交于 2019-12-01 17:41:00
问题 Tim is it possible to extract a list of row keys from the clsMatrix class? something like this... Sub KEYS() Dim KEY_LIST As Variant KEY_LIST = TABLES("UDLY").dR.KEYS End Sub I can then cycle through a table to extract a subset of data which meet a certain criteria. Tim, your code works well for one 2D matrix, but I have 5 tables to reference for the project to work. I tried using if...then else statements, but it's clumsy and doesn't work - the second pass looking for data from the BOOK

replacing items in nested lists python

╄→гoц情女王★ 提交于 2019-12-01 13:28:21
I am trying to make a duplicate list of lists and change one element to another within the nested lists of the duplicate list but am having some trouble. How I made the duplicate list: order = [['yhjK', 'F'], 'gap', ['bcsA', 'F'], ['bcsB', 'F'], ['bcsZ', 'F'], 'gap', ['yhjK', 'R']] #order_1 = list(order) #this makes the duplicate list as well order_1 = [] for x in order: order_1.append(x) How I changed the elements: for item in order_1: for n,i in enumerate(item): if i=='R': item[n]='F' if i=='F': item[n]='R' I want to replace all the 'F' with 'R' and vice versa. This accomplishes that but the

CSS on nested list : avoid styling of both lists

允我心安 提交于 2019-12-01 12:34:42
问题 I have the folowing nested list structure: HTML: <div id="my_nested_list"> <ul> <li> Item label <ul> <li>Subitem 1</li> <li>Subitem 2</li> <li>Subitem 3</li> </ul> <li> <li>...</li> </ul> </div> CSS: #my_nested_list>ul { /* first level list */ } #my_nested_list>ul>li { /* first level items */ } #my_nested_list>ul>li ul { /* second level list */ } #my_nested_list>ul>li ul>li { /* second level items */ } My problem is that with space selector instead of > , first level rules apply on the second

python how to change element in nested list [duplicate]

霸气de小男生 提交于 2019-12-01 10:49:42
This question already has an answer here: why can't I change only a single element in a nested list in Python [duplicate] 2 answers I have been using python for a lot and today I get surprised by a simple nested list. How can I change the value of an element of my list? >>> l=[[0,0]]*10 >>> l [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] >>> l[0] [0, 0] >>> l[0][0] 0 >>> l[0][0]=1 #here comes the question >>> l [[1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0]] >>> I would expect as final result l=[[1,0],[0,0],[0,0]...] Why it

Convert list of positions [4, 1, 2] of arbitrary length to an index for a nested list

泄露秘密 提交于 2019-12-01 06:11:43
Assuming this list nestedList = ["a", "b", [1, 2, 3], "c",[4, 5, 6, [100, 200, 300]], "d"] I have a function that returns a position list for a nested list of arbitrary depth. Examples : [2, 1] -> "2" [5] -> "d" [4, 3, 2] -> "300" As you can see it is not clear in the beginning how many levels of nesting there are. Additional Problem For list modifications I want to use the [:] or [4:] or [0:1] notations. For a human its very easy to do: simply add as many index position as you need to. nestedList[2][1] nestedList[5] nestedList[4][3][2] nestedList[4][1:] = NewItem + nestedList[4][1:] #insert

sum of first value in nested list

社会主义新天地 提交于 2019-12-01 05:51:15
In traditional python, the sum function gives the sum of a list : sum([0,1,2,3,4])=10 On the other hand, what if you have a nested list as so: sum([[1,2,3],[4,5,6],[7,8,9]]) We find the error: Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'list' In addition to this, how could we find the sum of the first values (index 0) in a nested list? Such as: something([[1,2,3],[4,5,6],[7,8,9]])=12 To get the sum of all the first elements you need to have a generator expression >>> a = [[1,2,3],[4,5,6],[7,8,9]] >>> sum(i[0]

Convert list of positions [4, 1, 2] of arbitrary length to an index for a nested list

本秂侑毒 提交于 2019-12-01 05:27:36
问题 Assuming this list nestedList = ["a", "b", [1, 2, 3], "c",[4, 5, 6, [100, 200, 300]], "d"] I have a function that returns a position list for a nested list of arbitrary depth. Examples : [2, 1] -> "2" [5] -> "d" [4, 3, 2] -> "300" As you can see it is not clear in the beginning how many levels of nesting there are. Additional Problem For list modifications I want to use the [:] or [4:] or [0:1] notations. For a human its very easy to do: simply add as many index position as you need to.