nested-lists

Sencha Touch 2: Insert into TreeStore/NestedList

谁都会走 提交于 2019-12-07 03:04:07
问题 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

Processing a sub-list of variable size within a larger list

不羁的心 提交于 2019-12-06 16:07:52
I'm a biological engineering PhD student here trying to self-learn Python programming for use in automating a part of my research, but I've ran into a problem with processing sub-lists within a bigger list that I can't seem to solve. Basically, the goal of what I'm trying to do is write a small script that will process a CSV file containing a list of plasmid sequences that I'm building using various DNA assembly methods, and then spit out the primer sequences that I need to order in order to build the plasmid. Here's the scenario that I'm dealing with: When I want to build a plasmid, I have to

how to produce a nested list from two lists in python

泄露秘密 提交于 2019-12-06 15:33:11
I am a newbie in python, I have two lists: l1 = ['a','b','c','d'] l2 = ['new'] i want to get new list like this l3 = [('a','new'),('b','new'),('c','new'),('d','new')] What is the best way to combine the two lists? >>> from itertools import product >>> l1 = ['a','b','c','d'] >>> l2 = ['new'] >>> list(product(l1,l2)) [('a', 'new'), ('b', 'new'), ('c', 'new'), ('d', 'new')] If l2 always just has the one element there is no need to overcomplicate things l3 = [(x, l2[0]) for x in l1] See the itertools docs . In particular, use product for a Cartesian product: from itertools import product: l1 = ['a

Remove all empty nested lists

岁酱吖の 提交于 2019-12-06 11:58:19
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? 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))) realli Recursion: def remove_lst(lst): if not isinstance(lst, list): return lst else: return [x for x in map(remove_lst, lst) if (x != [] and x != '')]

Return a list of all variable names in a python nested dict/json document in dot notation

扶醉桌前 提交于 2019-12-06 09:58:50
问题 I'm looking for a function that operates on a python arbitrarily nested dict/array in JSON-esque format and returns a list of strings keying all the variable names it contains, to infinite depth. So, if the object is... x = { 'a': 'meow', 'b': { 'c': 'asd' }, 'd': [ { "e": "stuff", "f": 1 }, { "e": "more stuff", "f": 2 } ] } mylist = f(x) would return... >>> mylist ['a', 'b', 'b.c', 'd[0].e', 'd[0].f', 'd[1].e', 'd[1].f'] 回答1: def dot_notation(obj, prefix=''): if isinstance(obj, dict): if

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

耗尽温柔 提交于 2019-12-06 07:03:16
问题 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

Recursively going through a list (python)

六眼飞鱼酱① 提交于 2019-12-06 03:19:16
Say I have a list x = [1, 2, 3, 4] Is there a recursive method where i can go through the list to find the value? I want to ultimately be able to compare a returned value in the list, (or nested list) to an arbitrary number to see it it matches. I can think a way to do this using a for loop, but i have trouble imagining a recursive method to do the same thing. I know that I can't set a counter to keep track of my position in the list because calling the function recursively would just reset the counter every time. I was thinking I could set my base case of the function as a comparison between

Plotting list of lists in a same graph in Python

杀马特。学长 韩版系。学妹 提交于 2019-12-06 02:30:07
问题 I am trying to plot (x,y) where as y = [[1,2,3],[4,5,6],[7,8,9]] . Say, len(x) = len(y[1]) = len(y[2]) .. The length of the y is decided by the User input. I want to plot multiple plots of y in the same graph i.e, (x, y[1],y[2],y[3],...) . When I tried using loop it says dimension error . I also tried: plt.plot(x,y[i] for i in range(1,len(y))) How do I plot ? Please help. for i in range(1,len(y)): plt.plot(x,y[i],label = 'id %s'%i) plt.legend() plt.show() 来源: https://stackoverflow.com

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

好久不见. 提交于 2019-12-05 23:05:49
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, import pdb import itertools x = [[2,3,3], [5,0,3]] y = [[0,3], [2,3,3,3]] for idx, (a, b) in enumerate

Replace a string in list of lists

谁说我不能喝 提交于 2019-12-05 20:33:33
问题 I have a list of lists of strings like: example = [["string 1", "a\r\ntest string:"],["string 1", "test 2: another\r\ntest string"]] I'd like to replace the "\r\n" with a space (and strip off the ":" at the end for all the strings). For a normal list I would use list comprehension to strip or replace an item like example = [x.replace('\r\n','') for x in example] or even a lambda function map(lambda x: str.replace(x, '\r\n', ''),example) but I can't get it to work for a nested list. Any