nested

Extracting the keys associated in previous levels nested dictionary

喜夏-厌秋 提交于 2019-12-05 15:58:43
I have a large nested dictionary with an unknown depth and i would like to know how i can find the keys which led to the value. For example... {'furniture':{'chair':{'sofa':{'cushion':{}}}}} Ideally what i am looking for is a function to determine the path to the value that i have entered. I have tried researching online and this is what i tried... def route(d,key): if key in d: return d[key] for k,v in d.items(): if isinstance(v,dict): item = route(v, key) if item is not None: return item This returns the items inside the key. I am looking to be able to extract the path which leads to that

Is there any possibility to reach the index of an outer QML Repeater from the inner one (they are nested)?

给你一囗甜甜゛ 提交于 2019-12-05 15:29:05
I am trying to dynamically build a matrix of the same type of items in my QML application and keep it dynamic, so that you can change the number of rows and columns in a c++ file anytime. This has been working well, but now, to access them individually, I want to give them dynamic names. Therefore I nested two repeaters and tried to set the objectName as in the following: Repeater{ id: rows model: Matrix1.row //number of rows in Matrix1-Object Repeater{ id: columns model: Matrix1.column //number of columns in Matrix1-Object RepeatedItem{ objectName: (index) +"."+ (rows.index) //matrix elements

in python, how do i iterate a nested dict with a dynamic number of nests?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 15:10:27
问题 OK by dynamic I mean unknown at runtime. here is a dict: aDict[1]=[1,2,3] aDict[2]=[7,8,9,10] aDict[n]=[x,y] I don't know how many n will be but I want to loop as follows: for l1 in aDict[1]: for l2 in aDict[2]: for ln in aDict[n]: # do stuff with l1, l2, ln combination. Any suggestions on how to do this? I am relatively new to python so please be gentle (although I do program in php). BTW I am using python 3.1 回答1: You need itertools.product. from itertools import product for vals in product

For loop using more than one list in Python [duplicate]

China☆狼群 提交于 2019-12-05 14:51:40
问题 This question already has answers here : Loop over 2 lists, repeating the shortest until end of longest (2 answers) How can I infinitely loop an iterator in Python, via a generator or other? (3 answers) Closed 13 days ago . I'm looking for solution to my problem. At the moment I have two list of elements: column_width = ["3", "3", "6", "8", "4", "4", "4", "4"] fade = ["100", "200", "300"] What I want to achieve is to create for loop which wil give me following output: column-3-fade-100 column

C++ private modifier ignored on nested anonymous struct

孤人 提交于 2019-12-05 14:17:42
问题 The following sample code compiles just fine in Visual C++: class Test { private: struct { struct { int privateData; }; }; }; int main(int, char **) { Test test; test.privateData = 0; return 0; } But why? I'd expect a compiler error because the privateData member should be inaccessible to the function main, since it's supposed to be private like its container's container. I know that nameless structs are not part of official C++, but this design is asinine. By the way I've also tried to

Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>();

微笑、不失礼 提交于 2019-12-05 13:00:39
Why doesn't that work in java, but this does Map<String, Map<String, Boolean>> myMap = new HashMap<String,Map<String,Boolean>>(); Just to clarify the below alteration of the nested HashMap shows a compiler error, whereas the above does not not; with a Map (not hashmap) Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>(); This is because generics in Java are invariant , i.e. even if class B is an A, a Collection<B> is not a Collection<A> . And this is for a good reason. If your example were legal, this would be possible: Map<String, HashMap<String, Boolean>>

Is there any performance difference for nested document in mongodb query

梦想与她 提交于 2019-12-05 12:57:25
问题 If I create an index for username field, which document is better for query a specific user? The nested one: { account:{ username:'zhengyi', passwd:'zhengyi', friends:[] } dev:{ os:'iOS', ver:'6.0', hw:'iPhone2,1' }, app:{ ver:'1.0', pver:'1.0' } } The unnested one: { username:'zhengyi', passwd:'zhengyi', friends:[], dev:{ os:'iOS', ver:'6.0', hw:'iPhone2,1' }, app:{ ver:'1.0', pver:'1.0' } } 回答1: It doesn't make a difference You're either doing: db.collection.findOne({"username":"zhengyi"});

Duplication of entity when change made by a child ManagedObjectContext is pushed (saved) to its parent

落爺英雄遲暮 提交于 2019-12-05 11:20:28
I expect (hope even) that this will be a stupid question, but after wrestling for many hours with this problem I need some insight. My iOS 5.1 app uses nested MOCs, having a PrivateQueueConcurrency child MOC, call it MOC-Child, whose parent is a MainQueueConcurrency MOC, call it MOC-Parent. MOC-Parent backs a table view that displays its entities. MOC-Child is used by a parser, which runs asynchronously on a non-main thread, to create new entities that correspond to XML entity-descriptions parsed from a URL connection, and then push the new entities to the MOC-Parent, via a save on the MOC

C++ nested classes, access fathers variables [duplicate]

人盡茶涼 提交于 2019-12-05 11:02:06
This question already has an answer here: Can inner classes access private variables? 5 answers The title already says a lot, but basically what i want to do is the following(Example): I have a class called A, and another class inside a called B, like so: class A { int a; class B { void test() { a = 20; } }; }; As you can see my goal is for class B to have access to class A, as it is a nested class. Not this wont work, because B doesn't have access to A, but how can it get access? Thank You Despite that you declared class B inside of A, classes A and B are still completely independent. The

Scheme Macro for nesting expressions

余生颓废 提交于 2019-12-05 10:38:27
Can a macro be written in Scheme (with define-syntax , for example) which will take expressions like this: (op a b c d e f g h i j) And yield expressions like this as output? (op (op (op (op (op (op (op (op (op a b) c) d) e) f) g) h) i) j) Of course, for arbitrary lengths. I can't think of a way to do it, given some template like this: (define-syntax op (syntax-rules () [(_) 'base-case] [(v1 v2 ...) 'nested-case??])) (define bop list) (define-syntax op (syntax-rules () ((op a b) (bop a b)) ((op a b c ...) (op (bop a b) c ...)))) For example, (op 1 2 3 4) expands to (bop (bop (bop 1 2) 3) 4)