nested-lists

Finding the index of an element in nested lists in python

牧云@^-^@ 提交于 2019-12-08 06:22:10
问题 I am trying to get the index of an element in nested lists in python - for example [[a, b, c], [d, e, f], [g,h]] (not all lists are the same size). I have tried using strand_value= [x[0] for x in np.where(min_value_of_non_empty_strands=="a")] but this is only returning an empty list, even though the element is present. Any idea what I'm doing wrong? 回答1: def find_in_list_of_list(mylist, char): for sub_list in mylist: if char in sub_list: return (mylist.index(sub_list), sub_list.index(char))

Remove duplicates in a list of lists based on the third item in each sublist

夙愿已清 提交于 2019-12-08 05:38:23
问题 I have a list of lists that looks like: c = [['470', '4189.0', 'asdfgw', 'fds'], ['470', '4189.0', 'qwer', 'fds'], ['470', '4189.0', 'qwer', 'dsfs fdv'] ...] c has about 30,000 interior lists. What I'd like to do is eliminate duplicates based on the 4th item on each interior list. So the list of lists above would look like: c = [['470', '4189.0', 'asdfgw', 'fds'],['470', '4189.0', 'qwer', 'dsfs fdv'] ...] Here is what I have so far: d = [] #list that will contain condensed c d.append(c[0])

Remove duplicates in a list of lists based on the third item in each sublist

流过昼夜 提交于 2019-12-08 03:24:31
I have a list of lists that looks like: c = [['470', '4189.0', 'asdfgw', 'fds'], ['470', '4189.0', 'qwer', 'fds'], ['470', '4189.0', 'qwer', 'dsfs fdv'] ...] c has about 30,000 interior lists. What I'd like to do is eliminate duplicates based on the 4th item on each interior list. So the list of lists above would look like: c = [['470', '4189.0', 'asdfgw', 'fds'],['470', '4189.0', 'qwer', 'dsfs fdv'] ...] Here is what I have so far: d = [] #list that will contain condensed c d.append(c[0]) #append first element, so I can compare lists for bact in c: #c is my list of lists with 30,000 interior

Exhaustive combinations of lists in python

房东的猫 提交于 2019-12-08 01:30:29
问题 I have a long list of lists in Python that looks something like this: myList=[ ('a',[1,2,3,4,5]), ('b',[6,7,8,9,10]), ('c',[1,3,5,7,9]), ('d',[2,4,6,8,10]), ('e',[4,5,6,7,8]) ] And I would like to enumerate the common values exhaustively ('a:b', ), ('a:c', [1,3,5]), ('a:d', [2,4]), ('a:e', [4,5]), ('b:c', [7,9]), ('b:d', [6,8,10]), ('a:c:e', [5]), ('b:c:e', [7]), ('b:d:e', [6,8]), and the same for groups of four, five, six until all common values have been identified (assuming the lists were

How to add two nested lists in parallel and append result to a new list in python

依然范特西╮ 提交于 2019-12-07 17:55:38
问题 I'm trying to add all the elements of two unequal nested lists in parallel and append the result back to another new list, i've written a little hacky code that could add them but there's a lot of things wrong with the code, first i tried to make the pairs equal by appending 0's to the end of the list but the code still runs into the problems since the length of the first pair is 3 and the length of the second pair is 4, i also tried using map but i couldn't add an integer and a NoneType,

Cast Nested List<X> to Nested List<Y>

守給你的承諾、 提交于 2019-12-07 11:38:50
问题 I know its possible to cast a list of items from one type to another but how do you cast a nested list to nested List . Already tried solutions: List<List<String>> new_list = new List<List<string>>(abc.Cast<List<String>>()); and List<List<String>> new_list = abc.Cast<List<String>>().ToList(); Both of which give the following error: Unable to cast object of type 'System.Collections.Generic.List 1[System.Int32]' to type 'System.Collections.Generic.List 1[System.String]'. 回答1: You can use Select

React Native nested ListView triggers onEndReached multiple times on loading

若如初见. 提交于 2019-12-07 10:27:33
问题 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}

python how to search an item in a nested list

冷暖自知 提交于 2019-12-07 09:39:58
问题 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? 回答1: >>> [x for x in li if 'ar' in x[2]] [['0', '20', 'ar'], ['50', '199', 'bar'], ['24',

Creating a nested UL from flat array in PHP

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 04:55:28
This is an array that was built from a JSON file. What I want to do is create a unordered nested list. I have seen a lot of tutorials out there but they usually only work for a simple (id, parent id, name) layout. This array is more complicated than that which is why my attempts don't seem to work. This is the desired outcome: Standard I: Curriculum, Planning, and Assessment Indicator I-A. Curriculum & Planning I-A-1. Child and Adolescent Development content will go in here I-A-2. Child and Adolescent Development content will go in here More indicators here that are related to Standard I

Maximum value from a list of lists and its index

房东的猫 提交于 2019-12-07 03:30:48
问题 li = [[1,2], [2,3], [7,6]] How can I find the max value and its index efficiently? Suppose for li I want: max_value = 7 max_index = (2, 0) I can do this as below: max_value = 0 for row_idx, row in enumerate(alignment_matrix): for col_idx, col in enumerate(row): if col > max_value: max_value = col max_index = (row_idx, col_idx) But I need an efficient way without using too many unnecessary variables. 回答1: Using max and generator expression, you can express it more shortly: max_value, max_index