I am novice in Python and programming. Generators are a bit too complicated to understand for new programmers. Here's my theory on generator functions in Python:    Any function contains a yield statement will return a generator object  A generator object is a stack contains state Each time I call .next method Python extracts the function's state and when it finds another yield statement it'll bind the state again and deletes the prior state:    Example:    [    [state1] # Stack contains states and states contain info about the function   [state2] # State1 will be deleted when python finds the other yield?   ]    This is of course might be like the stupidest theory on earth, but forgive me I am just new in the coding word.  My Questions:     What Python internally makes to store the states ?  Does yield statement adds a state to a stack if it exists ? What yield creates internally ? I understand yield creates a generator object, however, I wonder what generator objects contain that makes them work ? are they just a stack/list of states and we you use .next method to extract each state and Python will call the function with the indexed state automatically for instance ?
What is the use of the yield keyword in Python? What does it do? For example, I'm trying to understand this code1: def _get_child_candidates(self, distance, min_dist, max_dist):     if self._leftchild and distance - max_dist &lt; self._median:         yield self._leftchild     if self._rightchild and distance + max_dist &gt;= self._median:         yield self._rightchild    And this is the caller: result, candidates = [], [self] while candidates:     node = candidates.pop()     distance = node._get_dist(obj)     if distance &lt;= max_dist and distance &gt;= min_dist:         result.extend(node._values)     candidates.extend(node._get_child_candidates(distance, min_dist, max_dist)) return result  What happens when the method _get_child_candidates is called? Is a list returned? A single element? Is it called again? When will subsequent calls stop?   1. This piece of code was written by Jochen Schulz (jrschulz), who made a great Python library for metric spaces. This is the link to the complete source: [Module mspace][1].
Bring back review numbers to the top bar Though I never quite understood what those numbers were and they were quite ugly, they were the only reason I ever visited the reviews page.   Can we have similar functionality back on the top bar please? I have been playing for almost 2 days, and today it is asking me to sign up again.  I have all my game saved in my google account, but I wonder if I just log in from a trainer account will I keep my progress? Express $1 + \frac {1}{2} \binom{n}{1} + \frac {1}{3} \binom{n}{2} + \dotsb + \frac{1}{n + 1}\binom{n}{n}$ in a simplifed form I need to express $$1 + \frac {1}{2} \binom{n}{1} + \frac {1}{3} \binom{n}{2} + \dotsb  + \frac{1}{n + 1}\binom{n}{n}$$ in a simplified form.  So I used the identity $$(1+x)^n=1 + \binom{n}{1}x + \binom{n}{2}x^2 + \dotsb   + \binom{n}{n}x^n$$ Now on integrating both sides and putting $x=1$.  I am getting $$\frac{2^{n+1}}{n+1}$$ is equal to the given expression.But the answer in my book is  $$\frac{2^{n+1}-1}{n+1}.$$ Where does that -1 term in the numerator come from? Proving this relation is transitive Let $r$ be a relation on $A \times A$ such that $(a,b) r (c,d) \iff ad = bc.$ How can I show that this relation is transitive, ie. $(a, b)r(c,d)$ and $(c,d)r(e, f) \implies (a,b)r(e,f)$?  I tried to say that $(a,b) r (c,d)$ means that $c=ka$ and $d=kb,$ $k$ a coefficient, such that $ad = bc \iff akb = bka,$ and going on from there, but I'm not sure this is valid for all values of $a, b, c,$ and $d$. How can I show the transitivity of the relation? Am I Running as a Service Using Integration By Parts results in 0 = 1 I've run into a strange situation while trying to apply Integration By Parts, and I can't seem to come up with an explanation.  I start with the following equation:  $$\int \frac{1}{f} \frac{df}{dx} dx$$  I let:  $$u = \frac{1}{f} \text{ and } dv = \frac{df}{dx} dx$$  Then I find:  $$du = -\frac{1}{f^2} \frac{df}{dx} dx \text{ and } v = f$$  I can then substitute into the usual IBP formula:  $$\int udv = uv - \int v du$$  $$\int \frac{1}{f} \frac{df}{dx} dx = \frac{1}{f} f - \int f \left(-\frac{1}{f^2} \frac{df}{dx}\right) dx$$  $$\int \frac{1}{f} \frac{df}{dx} dx = 1 + \int \frac{1}{f} \frac{df}{dx} dx$$  Then subtracting the integral from both sides, I've now shown that:  $$0 = 1$$  Obviously there must be a problem in my derivation here...  What wrong assumption have I made, or what error have I made?  I'm baffled. Is "shined" correct? If so, is "he shined X on the tree" also correct? Recently, I overhead a former professor of mine use the word shined, a word that makes me grammatically uncomfortable.  She used it as following: "Then, after we shined a light on the other ball, what happened?..."  My first question is: Is using shined mainstream, over what sounds better to my ear, shone?  If so, is there any historical flip-flopping between the two usages?  Secondly, if shined is in fact legit, can it be used transitively?  Saying something like,      The light shined all throughout the night.   while odd, doesn't sound as bad to my ear as,     He shined the light on the ball throughout the night.   The latter sounds quite bad to my ear.  Indeed, à propos the original question, can shone &mdash; the better sounding alternative to my ear &mdash; be used transitively? How do I disable "Workspace dock" (a bottom panel with the list of open windows and a workspace indicator-cum-switcher), the one that is over "Plank" in the screenshot below?    I'm using Ubuntu 17.10. In order to better understand the SQL Server query processor, I've been thinking about how the ORDER BY clause works, and how SQL Server provides results.  It appears SQL Server will provide results in exactly the same order for any given set of data that remains the same and never, ever changes.  Once you introduce any kind of uncertainty such as developers changing something, the order of results can no longer be expected to be the same.  Simply seeing the results in the same order, each time you press F5 does not guarantee the results you expect.  Try this:  USE TempDB; DROP TABLE TestOrderBy; DROP TABLE TestOrderBy2; CREATE TABLE TestOrderBy (     ID INT NOT NULL CONSTRAINT PK_TestOrderBy PRIMARY KEY CLUSTERED IDENTITY(1,1)     , SomeData varchar(255) ); INSERT INTO TestOrderBy (SomeData) VALUES ('E'); INSERT INTO TestOrderBy (SomeData) VALUES ('D'); INSERT INTO TestOrderBy (SomeData) VALUES ('C'); INSERT INTO TestOrderBy (SomeData) VALUES ('B'); INSERT INTO TestOrderBy (SomeData) VALUES ('A');  CREATE TABLE TestOrderBy2 (     ID INT NOT NULL CONSTRAINT PK_TestOrderBy2 PRIMARY KEY CLUSTERED IDENTITY(1,1)     , SomeData varchar(255) ); INSERT INTO TestOrderBy2 (SomeData) VALUES ('E'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('D'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('C'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('B'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('A');  SELECT SomeData  FROM TestOrderBy UNION ALL SELECT SomeData FROM TestOrderBy2;  CREATE INDEX IX_TestOrderBy_SomeData ON TestOrderBy (SomeData); CREATE INDEX IX_TestOrderBy2_SomeData ON TestOrderBy2 (SomeData);  SELECT SomeData  FROM TestOrderBy UNION ALL SELECT SomeData FROM TestOrderBy2;   The results:    As you see, adding a simple index on the fields selected in the query alters the order of the results.  From here on, I'm adding ORDER BY unless I truly don't care. I can show that the following limit exists but I am having difficulties to find it. It is $$\lim_{n\to \infty} \sum_{k=1}^n \frac{k^n}{n^n}$$ Can someone please help me? Deriving the inverse of a 2x2 matrix What is a smart pointer and when should I use one? What is a smart pointer and when should I use one? I'm trying to create an item that can break certain blocks, but also has a colored name in 1.13.2   Here's the command I'm using.  /give iAugust minecraft:shears{display:{Name:"[{\"text\":\"Arcane Shears\",\"color\":\"aqua\",\"italic\":false,\"bold\":false}]CanDestroy:[minecraft:iron_bars]"}}   But it only has a colored name, and it can't break specific blocks. Is there any API function for shutting down Windows while installing any pending updates? Help! My party isn't challenged? While I've been running my campaign, I'm starting to get stumped. I am playing with a party of four, and we recently switched from 3.5 to Pathfinder, but the problem was the same in both situations.  No matter what I throw at the party, they seem to have no problems. Even if I put them up against something that is supposed to be 'Epic' or 'overwhelming' in terms of CR, they make out just fine. The one exception to this is when I had several encounters in one day that taxed them to near death. Usually I have about two encounters a day, but that day I had four encounters, with two of them being APL+1 and the other two being APL+2, and that was challenging. But other than that nothing seems to faze them!  How can I make the game more challenging without making it harder?  Just for reference, the party is fairly standard, and low level (level 4):   Wizard (tends to resort to mind-affecting spells, or grease if the creature is immune) Cleric (heals a lot, but always has spells / healing left over) Rogue (sneak attack, of course, which is more potent in Pathfinder) Fighter (gets enlarged and in-charge'd) How to enforce sender address to be "logged-in-user@example.org" in Postfix? I have set up a Postfix server with SMTP AUTH (STARTTLS on port 587). All my users are in the domain "example.org". I want to enforce the sender address to be "logged-in-user@example.org".  I learned that this can be achieved with the main.cf options  smtpd_sender_restrictions = reject_sender_login_mismatch, ... smtpd_sender_login_maps = hash:/etc/postfix/smtpd_sender_login_maps   with a login_maps file like:  a@example.org a b@example.org b c@example.org c ...   (see also ), but this would mean I'll have to edit the login_maps file every time I have a new user. I don't need such a flexible mapping: It should always be "logged-in-user@example.org". Is there an easier option? Let $X$ be a metric space. Prove that if every continuous function $f: X \rightarrow \mathbb{R}$ is bounded, then $X$ is compact.  This has been asked before, but all the answers I have seen prove the contrapositive. Realistically, this may be the way to go, but is there way to exhibit an unbounded continuous function (under the assumption $X$ is not compact) without appealing to results beyond introductory real analysis (e.g., the solution I've seen involves the Tietze Extension theorem)?  Because we're working with metric spaces, it's clear that the assumption that $X$ is noncompact (towards proving contrapositive) will lead us to extract a sequence of points in the space with no convergent subsequences. But how can we infer the existence of an unbounded continuous on the space knowing only about some sequence of points in this space (without using anything too advanced)? I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using  for extract and wrapping purposes, but it's not outputting anything.  preg_replace("/[A-Z]/", "&lt;span class=\"initial\"&gt;$1&lt;/span&gt;", $str) Determine $\text{Aut}(S)$ where $S = \mathbb{Q}[x]/(x^2)$ Here's the problem: if $S = \mathbb{Q}[x]/(x^2)$, compute the group  of automorphisms $\mbox{Aut}(S)$.   First off, I have the solution and I know it's isomorphic to the multiplicative group $\mathbb{Q}\backslash\{0\}$, so I'm trying to understand it. It uses what is called the substitution principle and the fact that the restriction of any endomorphism $\phi: \mathbb{Q}[x]\to \mathbb{Q}[x]$ to $\mathbb{Q}$ is the identity. It says that these two facts implies that the endomorphisms of $\mathbb{Q}[x]$ are in 1-1 correspondence with $h \in \mathbb{Q}[x]$, where the endomorphism corresponding to $h$ is $\phi_h : \mathbb{Q}[x] \to \mathbb{Q}[x]$ given by $\phi_h(f) = f(h)$ for $f \in \mathbb{Q}[x]$. I guess I just don't understand how it applied the substitution principle? It's probably obvious, but for some reason I am not getting it.  An explanation would be greatly appreciated! Or if you have a different solution, that'd be cool too. Thanks!! How to implement Bitcount using only Bitwise operators?