nested-lists

python how to search an item in a nested list

本小妞迷上赌 提交于 2019-12-05 16:06:49
say I have this list: li = [["0", "20", "ar"], ["20", "40", "asdasd"], ["50", "199", "bar"], ["24", "69", "sarkozy"]] Now, forget about the numbers, they are something that let me recognize the position of string. So basically, given that I have the string "ar" in hand, how can I extract all the lists that contain "ar"? new_li = [["50", "199", "bar"], ["24", "69", "sarkozy"]] How can I obtain this list? >>> [x for x in li if 'ar' in x[2]] [['0', '20', 'ar'], ['50', '199', 'bar'], ['24', '69', 'sarkozy']] 来源: https://stackoverflow.com/questions/6889785/python-how-to-search-an-item-in-a-nested

React Native nested ListView triggers onEndReached multiple times on loading

眉间皱痕 提交于 2019-12-05 13:04:10
Here's the code: <ScrollView> { tree.myPoiComments.CommentInfo && tree.myPoiComments.CommentInfo.length>0 && <FlatList data={tree.myPoiComments.CommentInfo} keyExtractor = {(item, index) => item.CommentId} ListHeaderComponent = {() => <View> <Text style={styles.listHeader}>My Comments</Text> </View>} renderItem= {({item}) => <CommentItem comment={item} owner={1} />} /> } { tree.poiComments.CommentInfo && tree.poiComments.CommentInfo.length>0 && <FlatList data={tree.poiComments.CommentInfo} keyExtractor = {(item, index) => item.CommentId} onEndReachedThreshold={1} onEndReached={(info) => {

Sencha Touch 2: Insert into TreeStore/NestedList

若如初见. 提交于 2019-12-05 08:09:16
I'm using a NestedList with a underlying TreeStore. Now I want to add items to the NestedList as leafs. How can I do this? Currently my code (Controller, onAddButtonTapped) looks like this: var store = Ext.getStore('menuStore'); var customerAreaNode = store.getRoot().getChildAt(1); customerAreaNode.appendChild({name: "text", leaf:true}); customerAreaNode.expand(); store.sync(); This code results in two new empty listentries on leaf level (behind the correct node) and one new listentry on node level. Every new entry has no names shown in the NestedList but every item contains "text" in their

jquery nested sortable list

十年热恋 提交于 2019-12-05 02:41:57
问题 i have this code $(document).ready(function() { $("#test-list").sortable({ items: "> li", handle : '.handle', axis: 'y', opacity: 0.6, update : function () { var order = $('#test-list').sortable('serialize'); $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); } }); $("#test-sub").sortable({ containment: "ul", items: "li", handle : '.handle', axis: 'y', opacity: 0.6, update : function () { var order = $('#test-list').sortable('serialize'); $("#info").load(

efficient algorithm instead of looping

荒凉一梦 提交于 2019-12-04 20:27:25
问题 I have a data set where each samples has a structure similar to this X=[ [[],[],[],[]], [[],[]] , [[],[],[]] ,[[][]]] for example: X=np.array([ [ [1,2,3], [2,4,5] ,[2,3,4] ] , [ [5,6], [6,6] ] , [[2,3,1],[2,3,10],[23,1,2],[1,4,5]] ] ,"object") Y=np.array([ [ [12,14,15] ,[12,13,14] ] , [ [15,16], [16,16] ] , [[22,23,21],[32,33,11],[12,44,55]] ] ,"object") so for every sample I need to calculate the dot product between every element of x with corresponding element of y of same index and sum the

Use … to modify a nested list within a functional

江枫思渺然 提交于 2019-12-04 18:02:44
问题 In R, I'm trying to create a way to transform function parameters given in ... to values in a pre-determined list within a closure function. I would like to be able to do something like this: function_generator <- function(args_list = list(a = "a", b = "b", c = list(d = "d", e = "e")){ g <- function(...){ ## ... will have same names as args list ## e.g. a = "changed_a", d = "changed_d" ## if absent, then args_list stays the same e.g. b="b", e="e" arguments <- list(...) modified_args_list <-

Convert Hierarchical DataTable to Json

ε祈祈猫儿з 提交于 2019-12-04 15:55:33
问题 I have a hierarchial data table as follows which generates menu and its sub menus. main menu has parentId as 0. Submenu has parent Ids referring to parentId. ResourceId DisplayName ParentId Url ----------------------------------------------- 1 Home 0 Some Url 2 Student 0 Some Url 3 Staff 0 Some Url 4 Library 0 Some Url 6 StudentAtt 1 Some Url 7 TimeTable 1 Some Url 8 Staff Att 2 Some Url 9 Book Issue 3 Some Url 10 Book Return 3 Some Url 11 Fee Payment 4 Some Url 12 Book fine 10 Some Url need

R: How do I remove the first element from each inner element of a list without converting it to matrix?

蹲街弑〆低调 提交于 2019-12-04 15:07:54
I have a list like that [[1]] [1] a1 b1 c1 [[2]] [1] a2 b2 c2 [[3]] [1] a3 b3 c3 I want specific element removed from each part of it: [[1]] [1] a1 c1 [[2]] [1] a2 c2 [[3]] [1] a3 c3 I tried tail but removes "outer" elements. Maybe some indexing would do? Assuming the pattern is just that you want the second element removed, lapply(List, function(x) x[-2]) Using purrr::map it would be even shorter by doing # setup some example data nestedList = list(list(4,5,6),list(1,2,3)) # remove first element from each sublist map(nestedList, tail, -1) 来源: https://stackoverflow.com/questions/34858384/r-how

Python — Russell's paradox (lists,not sets)

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:49:41
I know that one can create lists within lists. But how many, exactly can I fit in one. I tried this in the IPython console: In [1]: Alist = [1] In [2]: Alist.append(Alist) In [3]: Alist Out[3]: [1, [...]] In [4]: Alist[1] Out[4]: [1, [...]] In [5]: Alist[1][1] Out[5]: [1, [...]] In [6]: Alist[1][1][1] Out[6]: [1, [...]] Now I could go on forever trying to access Alist[1][1][1][1]...[1] , But how is this possible? Also, how come my machine hasn't run out of memory with this? I use Python2.7 on Ubuntu 16.04 if it helps. There is only one object of finite size here: You first create a list object

Navigate manually with a cursor through nested lists by only providing “left()” and “right()” as commands?

六月ゝ 毕业季﹏ 提交于 2019-12-04 13:08:05
问题 Eventhough I write in python I think the abstract concept is more interesting to me and others. So pseudocode please if you like :) I have a list with items from one of my classes. Lets do it with strings and numbers here, it really doesn't matter. Its nested to any depth. (Its not really a list but a container class which is based on a list.) Example : [1, 2, 3, ['a', 'b', 'c'] 4 ['d', 'e', [100, 200, 300]] 5, ['a', 'b', 'c'], 6] Note that both ['a', 'b', 'c'] are really the same container.