Questions tagged [nested]

This tag relates to any of various nested entities or operations in programming.

This tag relates to any of various nested entities in programming, including but not limited to:

  • Nested data structures
  • Nested queries
  • Nested calls to a procedure, subroutine, method or operation

For example, nesting queries in SQL means to create a subquery. Its result is used in the query itself and provides a query order and subsets.


Related tags :

16389 questions
202
votes
10 answers

How do you create nested dict in Python?

I have 2 CSV files: 'Data' and 'Mapping': 'Mapping' file has 4 columns: Device_Name, GDN, Device_Type, and Device_OS. All four columns are populated. 'Data' file has these same columns, with Device_Name column populated and the other three columns…
atams
  • 2,739
  • 3
  • 16
  • 14
199
votes
6 answers

Multiple levels of 'collection.defaultdict' in Python

Thanks to some great folks on SO, I discovered the possibilities offered by collections.defaultdict, notably in readability and speed. I have put them to use with success. Now I would like to implement three levels of dictionaries, the two top ones…
Morlock
  • 6,880
  • 16
  • 43
  • 50
177
votes
4 answers

How to re-raise an exception in nested try/except blocks?

I know that if I want to re-raise an exception, I simple use raise without arguments in the respective except block. But given a nested expression like try: something() except SomeError as e: try: plan_B() except AlsoFailsError: …
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
175
votes
16 answers

How to access outer class from an inner class?

I have a situation like so... class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # <-- this is the line in question How can I access…
T. Stone
  • 19,209
  • 15
  • 69
  • 97
153
votes
16 answers

How to use dot notation for dict in python?

I'm very new to python and I wish I could do . notation to access values of a dict. Lets say I have test like this: >>> test = dict() >>> test['name'] = 'value' >>> print(test['name']) value But I wish I could do test.name to get value. Infact I…
batman
  • 4,728
  • 8
  • 39
  • 45
152
votes
4 answers

How can I create a Set of Sets in Python?

I'm trying to make a set of sets in Python. I can't figure out how to do it. Starting with the empty set xx: xx = set([]) # Now we have some other set, for example elements = set([2,3,4]) xx.add(elements) but I get TypeError: unhashable type:…
Matt
  • 1,521
  • 2
  • 9
  • 3
142
votes
11 answers

Nested or Inner Class in PHP

I'm building a User Class for my new website, however this time I was thinking to build it little bit differently... C++, Java and even Ruby (and probably other programming languages) are allowing the use of nested/inner classes inside the main…
Lior Elrom
  • 19,660
  • 16
  • 80
  • 92
138
votes
8 answers

Can you write nested functions in JavaScript?

I am wondering if JavaScript supports writing a function within another function, or nested functions (I read it in a blog). Is this really possible?. In fact, I have used these but am unsure of this concept. I am really unclear on this -- please…
Red Swan
  • 15,157
  • 43
  • 156
  • 238
122
votes
7 answers

Nested classes' scope?

I'm trying to understand scope in nested classes in Python. Here is my example code: class OuterClass: outer_var = 1 class InnerClass: inner_var = outer_var The creation of class does not complete and I get the error:
user214870
121
votes
1 answer

List of HTML5 elements that can be nested inside P element?

I am trying to figure all the valid HTML5 elements that can be nested inside paragraph elements such that w3 validator doesn't show any errors. I mean I am trying to figure all tags that can replace the dots in the following code such that w3…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
120
votes
9 answers

Javascript "this" pointer within nested function

I have a question concerning how the "this" pointer is treated in a nested function scenario. Say I insert this following sample code into a web page. I get an error when I call the nested function "doSomeEffects()". I checked in Firebug and it…
JoJoeDad
  • 1,711
  • 3
  • 16
  • 15
117
votes
9 answers

Nested function in C

Can we have a nested function in C? What is the use of nested functions? If they exist in C does their implementation differ from compiler to compiler?
Sachin
  • 20,805
  • 32
  • 86
  • 99
115
votes
8 answers

namespaces for enum types - best practices

Often, one needs several enumerated types together. Sometimes, one has a name clash. Two solutions to this come to mind: use a namespace, or use 'larger' enum element names. Still, the namespace solution has two possible implementations: a dummy…
xtofl
  • 40,723
  • 12
  • 105
  • 192
114
votes
3 answers

LESS CSS nesting classes

I'm using LESS to improve my CSS and am trying to nest a class within a class. There's a fairly complicated hierarchy but for some reason my nesting doesn't work. I have this: .g { float: left; color: #323a13; .border(1px,#afc945); …
newbie_86
  • 4,520
  • 17
  • 58
  • 89
110
votes
14 answers

Can a 'for' loop inside of a 'for' loop use the same counter variable name?

Can I use the same counter variable for a for loop inside of a for loop? Or will the variables affect each other? Should the following code use a different variable for the second loop, such as j, or is i fine? for(int i = 0; i < 10; i++) { …
Uclydde
  • 1,414
  • 3
  • 16
  • 33