I am having trouble trying to sort a list of dictionaries based on a value matching a string. Here's an example:  test = [{'username': "1", "password": "test1"},         {"username": "3", "password": "test2"},         {"username": "5", "password": "test3"}]   I would like to sort this dictionary based on password = test3, so it would look like:  test = [{"username": "5", "password": "test3"},         {'username': "1", "password": "test1"},         {"username": "3", "password": "test2"}]   Any help would be appreciated. Thank you!
I have a list of dictionaries and want each item to be sorted by a specific value. Take into consideration the list: [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]  When sorted by name, it should become: [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}]
Reading through my textbook I came across the following problem and I am looking for some help solving it.  Prove that,  $$\binom{3n}{r}=\binom{3n-1}{r} + \binom{3n-1}{r-1}$$  In a previous problem I solved the following but I wasn't sure how to use it to prove the question above. Prove,  $$\binom{n}{r}=\binom{n}{n-r}$$  Solution:  left Side,  $$\binom{n}{r}=\frac{n!}{(n-r)!r!}$$  right side,  $$\binom{n}{n-r}=\frac{n!}{(n-(n-r))!(n-r)!} = \frac{n!}{(n-r)!r!}$$  Therefore completing the proof,  but how do I solve my first question? thanks! Expressing the area of the cross section of a cylinder I was able to solve similar questions where a triangle was involved, but this one has had me looping and pondering on it for the past week.  The Condition: Let $r$ be a positive constant. Consider the cylinder $x^2+y^2\leq r^2$ and let C be  part of the cylinder that satisfies $0\leq z\leq y$.  The questions:  (1) Consider the cross section of $C$ by the plane $x=t(-r\leq t\leq r)$ and express its area in terms of $r,t$  (2) Calculate the volume of $C$, and express it in terms of $r$.  (3) Let $a$ be the length of the arc along the base of the circle $C$ from the point $(r,0,0)$ to the point $(r cos\theta,r sin\theta,0)(0\leq\theta\leq\pi)$. Let $b$ be the length of the line segment from the point $(r cos\theta, r sin\theta, 0)$ to the point $(r cos\theta, r sin\theta, r sin\theta)$. Express $a$ and $b$ interms of $r,\theta$  (4)Calculate the are of the side of $C$ with $x^2+y^2=r^2$, and express it in terms of $r$.  Here are the expected answers(which I keep failing to get to):  (1) $\frac{1}{2}(r^2-t^2)$  (2) $\frac{2}{3}r^3$  (3) $r\theta$ and $r sin\theta$  (4) $2r^2$ How do I boot into single-user mode from GRUB? Round a double to 2 decimal places How can I give other drives and partitions short, meaningful names in nautilus? In nautilus and Unity the external drive has a nice short descriptive name "mcat", but all partitions on the 4 internal drives are displayed as a size (834 GB filesystem) or a huge 32-character string form of a GUID:  I'm guessing the external drive is nice, short, sweet and readable because that drive may have no partitions (well, just one I guess) and that name may be the drive label, whereas partitions usually don't have names. That may explain my problem, but doesn't solve it.  Is there some way to give reasonable names to these partitions in nautilus and Unity? Is it safe to change the lens on my new DSLR? I recently bought myself a shiny new DSLR camera. Before I can use it, I had to do something kind of terrifying: mount the lens.  Now of course, half the advantage of SLR cameras is that the lenses are interchangeable. But sitting there holding an extremely expensive brand new camera and staring into its bare innards, I'm just terrified that if I make one wrong move, a hair or a piece of dust could fall in there, and then the camera will be irreparably damaged and I'll never be able to use it again.  This might sound like a stupid question, but&hellip; is it actually &ldquo;safe&rdquo; to change the lens on the camera? Is this likely to destroy it?  (Obviously it goes without saying that you should limit the time spent with no lens attached to the minimum number of seconds possible. But even if you have lightning fingers, the camera will still be lenseless for some number of seconds. And it's not like I'm standing in a class 100 cleanroom here! Besides, you don't want to be too rough with the delicate lens mounting either&hellip;) New global search doesn't like tags SQL Switch/Case in 'where' clause Which Stack Exchange sites use MathJax? As the title says, I could use an exhaustive list of all Stack Exchange sites that use MathJax.  If the list included any site-specific customizations made to the MathJax configuration on each site, that would be even better. Let $f(z)$ be an entire function whose real part is bounded by a polynomial in $|z|$. Does it follow that $f(z)$ is a polynomial?  Or, without loss of generality and more suggestively $$(f(z)=\sum_{k=0}^\infty a_k z^k \quad \land \quad \operatorname{Re}(f(z))\leq |z|^n)\quad \forall z\in \mathbb{C} \qquad \Rightarrow \qquad f(z)=\sum_{k=0}^n a_k z^k \quad\forall z\in \mathbb{C}$$ Is the set of real matrices diagonalizable in $\mathcal M_n(C)$ dense in the set of all companion matrices? How do you greet multiple recipients in an e-mail? How do you greet multiple recipients in an e-mail?  Assuming they're both male, I just use "Sirs", but it seems a bit informal. Configure HAProxy to include host headers for different backends I am exploring the use of HAProxy as a balancer in front of a set of web apis that run on IIS.   node1.myapp.mycompany.com node2.myapp.mycomapny.com   We are currently using Host Headers to correctly resolve the right web application on IIS.  For example, we may have otherapp.mycompany.com running on the same server/port, but using Host Headers IIS knows which one to serve up.  My initial attempt at HAProxy left me with 404 errors, because I was not including the host headers in my request, and so IIS was serving back the default site bound to the given IP, and not resolving by host name.    The fix left me with something like this:  frontend localnodes     bind *:80     mode http     default_backend nodes  backend nodes     mode http     balance roundrobin     option forwardfor     reqirep ^Host: Host:\ node1.myapp.mycompany.com     server web01 node1.myapp.mycompany.com:80   This works great for a single backend, but I am left scracthing my head on how to include the correct host headers depending on which backend is serving up the request:  backend nodes     mode http     balance roundrobin     option forwardfor     reqirep ^Host: Host:\ node1.myapp.mycompany.com     server web01 node1.myapp.mycompany.com:80     server web02 node2.myapp.mycompany.com:80   The above does not work whenever node2 is used because it doesn't resolve correctly in IIS (node2 in this case is on a different server, and therefore different IP.  In fact, if they were running on the same server/ip I suspect the request work "work", but they would all be served by node1 per the host header).     Is it possible to set the host based on the url of the backend used to serve up the request? If so, this implies my checks also need to provide the correct host header based on backend, how would that be done?   Edit: Am using HA-Proxy version 1.7.9 2017/08/18  Let me give this just a little more background.  We used to have just myapp.mycompany.com serving up api requests.  We need to expand it.  Our clients will still call myapp.mycompany.com, but that will just point to the HAProxy, which will balance it out to node1.myapp.mycompany.com and node2.myapp.mycompany.com.  Our current server configurations have us binding a single IP address on each server, so we use host headers to resolve. EM algorithm gaussian mixtures- derivation I'm trying to make sense of a derivation I'm following from the lecture notes of Stanford's ML course.  Specifically the notes are here:   I'm particular I'm interested in the step where they are optimizing the lower bound of the log-likelihood by finding the derivative of that function w.r.t the mean (top of page 7). I'm a bit stuck on going from line 1 to line 2 in that sequence.  To copy here (using abbreviated notation for space):  $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\log\frac{\alpha_j \exp\psi_{j}^{(i)}\phi_j}{w_j^{(i)}}  \qquad(1) $$ $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\psi_{j}^{(i)}\qquad(2) $$ where $\psi_{j}^{(i)} =-\frac{1}{2}(x^{(i)}-\mu_j)^T\Sigma^{-1}_{j}(x^{(i)}-\mu_j)$ and $\alpha_j=\frac{1}{(2\pi)^{n/2}|\Sigma_j|^{1/2}}$.  The quantity $\mu_s$ is the mean (of a multivariate gaussian distribution) for class $s$.    In short, I'm not sure how they get from (1) to (2).  From just changing the log of (1) I see:  $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\log \left(\alpha_j \exp\psi_{j}^{(i)}\phi_j\right) - w_j^{(i)}\log w_j^{(i)} \qquad(1) $$  To get to their form (2) my impression is that they take pre-emptively discard terms that would contain derivatives of $w_j^{(i)}$ (w.r.t. $\mu_s$).  At least if you assume that much, you get to (2).  However, as they show earlier in that PDF,  $$ w_j^{(i)} = p(z^{(i)}=j | x^{(i)}) =\frac{p(x^{(i)}|z^{(i)}=j)p(z^{(i)}=j) }{\sum_j p(x^{(i)},z^{(i)}=j) } $$ i.e. this quantity is the posterior distribution of the class labels.  Intuitively, it seems like $\partial w_j^{(i)}/ \partial \mu_s$ should be non-zero.  After all, changing the location of the mean $\mu_s$ would change your posterior probability for a particular class given the same data.  (Right?).  Just from a mechanical point of view, $\partial w_j^{(i)}/\partial \mu_j$ would seemingly have some non-zero terms since $p(x^{(i)}|z^{(i)}=j) \sim \mathcal{N}(\mu_j, \Sigma_j)$.  If I work through the algebra, I get  $$ \frac{\partial w_j^{(i)}}{\partial \mu_j} = w_j^{(i)}(1-w_j^{(i)})\frac{\partial \psi^{(i)}_{j}}{\partial \mu_j} $$  What am I missing here?  If I take the log-likelihood (without even thinking about EM algorithm),    $$ \ell = \sum_{i=1}^{m}\log \sum_{j=1}^{k}p(x^{(i)}|z^{(i)}=j)p(z^{(i)}=j) $$ and differentiate w.r.t $\mu_s$, I correctly get  $$ \mu_s^* = \frac{\sum_{i=1}^{m}w_s^{(i)}x^{(i)}}{\sum_{i=1}^{m}w_s^{(i)}} $$  so I'm comfortable with the eventual result, just not the intermediate steps. I am very confused about how to compute  $$\sum_{n=0}^{\infty}nk^n.$$  Can anybody help me? Creating a unique alphanumeric 10-character string I'm looking to create a simple short-lived reservation system, and I'd like to generate confirmation numbers that are   unique random-looking alphanumeric short-ish, at least much shorter than 32 character-long strings returned by sha1   I'm only looking to have ~500 reservations, so I don't imagine high likelyhood of collissions.  One idea I had is generate an sha1 hash based on a date-time stamp and username, then truncating it to its first 10 characters.  Would something like that be reliably unique enough for the purposes of processing ~500 reservations? How can I prove that $xy\leq x^2+y^2$? How can I prove that $xy\leq x^2+y^2$ for all $x,y\in\mathbb{R}$ ? Center figure that is wider than \textwidth I have a figure that is wider than the \textwidth of my document. (I don't want to change the \textwidth.) As a result, the leftmost part of the figure is flush with the left margin, while the rightmost part spills into the right margin too much. I'd like to center the figure, so that it will exceed the \textwidth equally on both sides. How to include audio file in PDF How do I include audio file, or should I say, link to audio file in PDF?   Audio should be playable "from PDF directly", without opening any additional window. Is it possible to attach audios to PDF     then so I can manipulate only with     that file, without being bothered     with copying folders where those     audio files would reside?   I saw that 1. is definitely doable (but don't know how) and I'm interested if second one is also possible (while compiling .tex file) since I know that some files (like graphs and tables) can be attached in PDF, but after it's generated.   Button for playing audio from document that uses this trick. Is convex hull of a finite set of points in $\mathbb R^2$ closed? Is the convex hull  of a finite set of points in $\mathbb R^2$ closed? Intuitively, yes. But not sure how to show that. Thanks!