nested-lists

Converting list of lists / nested lists to list of lists without nesting

﹥>﹥吖頭↗ 提交于 2019-12-10 20:59:01
问题 I want to convert my list of lists and within these lists there are list into only list of lists. For example: My code: a = [[], [], [['around_the_world']], [['around_the_globe']], [], [], [], []] aaa = len(a) aa = [[] for i in range(aaa)] for i, x in enumerate(a): if len(x) != 0: for xx in x: for xxx in xx: aa[i].append(xxx) print(aa) Currently: a = [[], [], [['around_the_world']], [['around_the_globe']], [], [], [], []] to expected: [[], [], ['around_the_world'], ['around_the_globe'], [], [

Sencha Touch 2: 'specified Store cannot be found'

帅比萌擦擦* 提交于 2019-12-10 18:38:09
问题 I'm trying to load JSON data into a NestedList. I have the following store file in /app/store/Exhibits.js Ext.define('VisitTCMIndy.store.Exhibits',{ requires: ['VisitTCMIndy.model.Exhibit', 'Ext.data.proxy.JsonP'], extend: 'Ext.data.TreeStore', config: { model: 'VisitTCMIndy.model.Exhibit', proxy: { type: 'jsonp', url: 'http://www.example.com/explore.php', reader: { type: 'json', rootPropery: 'children' } } } }); Then I reference it in the following view in /app/view/Explore.js Ext.define(

Is it possible to index nested lists using tuples in python?

六眼飞鱼酱① 提交于 2019-12-10 14:24:16
问题 I just started with python and very soon wondered if indexing a nested list with a tuple was possible. Something like: elements[(1,1)] One example where I wanted to do that was something similar to the code below in which I save some positions of the matrix that I will later need to access in a tuple called index. index = ( (0,0), (0,2), (2,0), (2,2) ) elements = [ [ 'a', 'b', 'c'], [ 'c', 'd', 'e'], [ 'f', 'g', 'h'] ] for i in index: print (elements [ i[0] ] [ i[1] ]) # I would like to do

Remove all empty nested lists

血红的双手。 提交于 2019-12-10 10:34:17
问题 How to from this list: list = [ [], ['', 'subitem'], [[]], 'item', [ 'item', 'item', [''], [] ], [] ] I can get this: list = [ ['subitem'], 'item', [ 'item', 'item' ] ] How do I remove recursively all empty nested lists, zero-strings, and lists with nested zero-strings? 回答1: A one-liner: def remove_empty(l): return tuple(filter(lambda x:not isinstance(x, (str, list, tuple)) or x, (remove_empty(x) if isinstance(x, (tuple, list)) else x for x in l))) 回答2: Recursion: def remove_lst(lst): if not

How to concat lists in erlang without creating nested lists?

▼魔方 西西 提交于 2019-12-09 17:14:22
问题 I'm trying to be a good erlanger and avoid "++". I need to add a tuple to the end of a list without creating a nested list (and hopefully without having to build it backwards and reverse it). Given tuple T and lists L0 and L1: When I use [T|L0] I get [tuple,list0] . But when I use [L0|T] , I get nested list [[list0]|tuple] . Similarly, [L0|L1] returns [[list0]|list1] . Removing the outside list brackets L0|[T] produces a syntax error. Why is "|" not symmetric? Is there a way to do what I want

Python - sort a list of nested lists

爱⌒轻易说出口 提交于 2019-12-09 14:32:43
问题 I have input consisting of a list of nested lists like this: l = [[[[[39]]]], [1, 2, 3], [4, [5, 3], 1], [[[[8, 9], 10], 11], 12]] I want to sort this list based on the sum of all the numbers in the nested lists... so, the values I want to sort by of l would look like this: [39, 6, 13, 50] Then I want to sort based on these. So the output should be: [[1, 2, 3], [4, [5, 3], 1], [[[[39]]]], [[[[8, 9], 10], 11], 12]] What's a nice pythonic way of doing this? 回答1: A slight simplification and

Convert a mixed nested list to a nested tuple

烂漫一生 提交于 2019-12-08 11:40:36
问题 If I have easy_nested_list = [['foo', 'bar'], ['foofoo', 'barbar']] and would like to have (('foo', 'bar'), ('foofoo', 'barbar')) I can do tuple(tuple(i) for i in easy_nested_list) but if I have mixed_nested_list = [['foo', 'bar'], ['foofoo', ['foo', 'bar']],'some', 2, 3] and would like to build a tuple out of this, I don't know how to start. It would be nice to get: (('foo', 'bar'), ('foofoo', ('foo', 'bar')), 'some', 2, 3) The first problem is that Python turns my string into a tuple for

Get level of items in a nested list

只愿长相守 提交于 2019-12-08 09:37:27
问题 Problem: I have some linked data and I want to build a structure like this one on this picture : and get the level of each item because in the future I will make some calculations by staring at the lowest level of my tree structure. Expected Result: I need to get a structure that gives me items per level : level 0: A level 1: A = B, C,D level 2: D = E, F, G level 3: E = H,I , J, K what I have tried so far: I've tried this recursive code to simulate the behavior but I'm unable to get items the

Nested Bulleted lists in Novacode docx

落花浮王杯 提交于 2019-12-08 09:23:28
问题 How can i create nested bulleted/Ordered lists with Novacode for docx? I've done some research but couldn't find anything, any help is appreciated. 回答1: Hope it's not too late, I've just figured it out a couple hours ago class Program { static void Main(string[] args) { string docPath = "PATH TO YOUR OUTPUT WORD DOCUMENT" ; var doc = DocX.Create(docPath); var l = doc.AddList("Item #1", 0, ListItemType.Bulleted, 0); doc.AddListItem(l, "Item #2"); doc.InsertList(l); doc.Save(); } } 回答2: You

Select sub-list with highest integer value in a specified position

╄→гoц情女王★ 提交于 2019-12-08 08:17:48
问题 I have a nested list: nested_list = [['a', 3], ['a', 1], ['a', 5]] How do I iterate over this list, select the sublist with the max integer value? holder = [] for entry in nested_list: tmp = sublist with max entry[2] value holder.append(tmp) I am stuck on coding the second line. 回答1: try: max(nested_list, key=lambda x: x[1]) or import operator max(nested_list, key=operator.itemgetter(1)) If the first item will always be 'a' , you can just do max(nested_list) If you're willing to dive into