If I create a list with an empty dictionary in it, then multiply that list by a number, it seems that instead of adding more dictionaries to the list, python just populates the list with more references to the same dictionary.  &gt;&gt;&gt; d = [{}]*3 &gt;&gt;&gt; d[0]["x"] = 43 &gt;&gt;&gt; d [{'x': 43}, {'x': 43}, {'x': 43}]   As you can see, adding an element in one of the dictionaries leads to insertion into all of them, which means that there is in fact only one dictionary, with three pointers in d to it.  Why is this? What is the best way to add a number of empty dicts to a list in Python?
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
Inverting Polygons using QGIS? I have a Shapefile with Polygon features  representing the world's land areas (continents, islands).   Is it possible to invert these, and get a geometry that represents the world's oceans and seas?   So the original land Polygons need to become rings in a single global Polygon that covers the planet.  Basically, I'm looking for something like Select > Inverse in Photoshop.   I am using QGIS. Graph vertex chromatic number in a union of 2 sub-graphs $G_1$ is graph on the set of vertices $\{1,2,3,4,5,6,7,8\}$, $G_1$ vertex chromatic number is 5. $G_2$ is graph on the set of vertices $\{7,8,9,10,11,12,13,14,15,17,18,19,20\}$, $G_2$ vertex chromatic number is 7. We know $G_1$ and $G_2$ have an edge between vertex 7 and vertex 8. (We already used 2 different colors on them both). $G$ is graph on the set of vertices $\{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20\}$, and its set of edges is the union of the edges set of $G_1$ with the edges set of $G_2$. The vertex chromatic number of $G$ is: 5 / 7 / 12 / we can't know without further information Prove the answer. I think I got it, can someone approve? After the union to $G$, we copy the colors of $G_2$ to 7,8,9,10,11,12,13,14,15,16,17,18,19,20, obviously, $G$ vertex chromatic number is 7 and can't be less. We go through the vertices 1,2,3,4,5,6,7,8. We look for a vertex that doesn't connect to a different vertex. (There must be one, because if only one edge was missing in $G_1$, our chromatic number of $G_1$ was 7, but it's 5). Once we find a missing edge, we color both its vertices in the same color. We go through vertices 1-6, and color each vertex that doesn't have a color, with the colors of $G_2$ that we didn't use in $G_1$ (there should be 4-5 of them). Hilbert space of harmonic oscillator: Countable vs uncountable? Hm, this just occurred to me while answering another question:   If I write the Hamiltonian for a harmonic oscillator as $$H = \frac{p^2}{2m} + \frac{1}{2} m \omega^2 x^2$$ then wouldn't one set of possible basis states be the set of $\delta$-functions  $\psi_x = \delta(x)$, and that indicates that the size of my Hilbert space is that of $\mathbb{R}$.  On the other hand, we all know that we can diagonalize $H$ by going to the occupation number states, so the Hilbert space would be $|n\rangle, n \in \mathbb{N}_0$, so now the size of my Hilbert space is that of $\mathbb{N}$ instead.  Clearly they can't both be right, so where is the flaw in my logic? I'm working on this problem from Elementary Analysis by Ross which is intuitive when sketched but keeps stymieing me when I try to write it out.  Let $f$ be a continuous function on $[a,b] \subset \mathbb{R}$. Define $f^\star (x)$ as:  $$ f^\star(x) = \sup \{f(y)\mid a \leq y \leq x \} $$ Prove that $f^\star$ is a continuous increasing function on $[a,b]$.  Things I've figured out: (these are mostly trivial)   $f$ is uniformly continuous on $[a,b]$. Since $[a,b]$ is closed and bounded there exists some $c \in [a,b]$ such that $f(c) \geq f(x)\ \forall x \in [a,b]$. (In words: the supremum is actually attained.) If $c \in [a,b]$ is as above, then $f^\star$ is constant (and hence continuous) on $[c,b]$ (which is possibly a singleton).   This seems completely obvious when you actually draw a continuous function but translating that to a formal proof eludes me... Since humans are not large in mass, do we exert enough gravitational force for a small object to orbit around us? (Assuming that the only gravitational force acting on the object is from the human). Using Newton's law of gravity and using myself as the human mass, I exert a 10^-8 force on a 1 kg object .5 meter away, but I am not sure if even this small of a force will be acceptable. What is the baseline "force" between two objects for 1 to orbit another?  Edit: I am not sure if this is a SpaceExchange question. How to get the length of longest string in an array From :     "[...] the stress vector $T$ across a surface will always be a linear function of the surface's normal vector $n$, the unit-length vector that is perpendicular to it. [...] The linear relation between $T$ and $n$ follows from the fundamental laws of conservation of linear momentum and static equilibrium of forces, and is therefore mathematically exact, for any material and any stress situation. The components of the Cauchy stress tensor at every point in a material satisfy the equilibrium equations (Cauchy’s equations of motion for zero acceleration). Moreover, the principle of conservation of angular momentum implies that the stress tensor is symmetric."   What is the more detailed explanation for this, and/or where can I find it? USB WiFi dongle device that can emulate a virtual mass storage device for a home video player Is there a USB WiFi dongle device that can:   Emulate a virtual mass storage device for a home video player But in fact shows the files from a network-shared folder? Prove that for every $n\geq m \geq1$ natural numbers, the following number is an integer:  $${\gcd(n,m)\over n}\cdot{n\choose m}$$  Where $\gcd$ is the greatest common divisor.  I tried to make it simpler by cancelling the $n$ from the left side, and making it $(n-1)!$ on the right: $\gcd(n, m) \cdot \frac{(n-1)!}{m!(n-m)!}$, but can't really go further.   This was problem B-2 on the . Plot x=3 in PGFPlots Message appearing when a user was removed.     It seems I lost 1765 reputation points on Stack Overflow yesterday. The reason given in my history is "removed", with the description of "User was removed ()". I don't understand what that means. What caused this? The problem: The links at the bottom of the Stack&nbsp;Exchange newsletter link to a YouTube video instead of the right place on the website. I´m not sure if this is an oversight or a clever hack.  Screenshot: What does an ampersand after this assignment operator mean? If $|a| = 12, |b| = 22$ and $\langle a \rangle\cap \langle b\rangle \ne e$, prove that $a^6 = b^{11}$ How to run 32-bit app in Ubuntu 64-bit? I installed Ubuntu 14.04 and the current Android development SDK, which contains 32-bit executables. I found that I cannot run those 32-bit binaries. Trying to start them from bash gives me an error: $ ./adb bash: ./adb: No such file or directory  It is there though: $ ls -al ./adb -rwxrwxrwx 1 thomas thomas 1231255 Jan 17 13:31 ./adb $ file ./adb ./adb: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped.   Same symptom for all the other 32-bit tools in the Android SDK. In olden days one could just install 32-bit libraries on 64-bit Ubuntu to get 32-bit support, but that does not seem to work anymore. How do I run 32-bit apps on a 64-bit Ubuntu distribution? Show that: $\lim\limits_{r\to\infty}\int\limits_{0}^{\pi/2}e^{-r\sin \theta}\text d\theta=0$ I would like to show $\lim\limits_{r\to\infty}\int_{0}^{\pi/2}e^{-r\sin \theta}\text d\theta=0$.  Now, of course, the integrand does not converge uniformly to $0$ on $\theta\in [0, \pi/2]$, since it has value $1$ at $\theta =0$ for all $r\in \mathbb{R}$.   If $F(r) = \int_{0}^{\pi/2}e^{-r\sin \theta}\text d\theta$, we can find the $j$th derivative $F^{(j)}(r) = (-1)^j\int_{0}^{\pi/2}\sin^{j}(\theta)e^{-r\sin\theta}\text d\theta$, but I don't see how this is helping.  The function is strictly decreasing on $[0,\pi/2]$, since $\partial_{\theta}(e^{-r\sin\theta})=-r\cos\theta e^{-r\sin \theta}$, which is strictly negative on $(0,\pi/2)$.  Any ideas? I want to justificate following equation:  $$\sum_{k=0}^n \frac{(-1)^k}{k!(n-k)!}\frac{1}{2k+1} = \frac{2^n}{(2n+1)!!}$$  I calculated the both sides for $n$ from 1 to 10 and it was true. How the mathematical induction can be applied to this equation? Or is there other way to justificate it? Prove that $\sum\limits_{k=0}^m\binom{m}k\binom{n}{r+k}=\binom{m+n}{m+r}$ using combinatoric arguments. Prove that $$\sum\limits_{k=0}^m\binom{m}k\binom{n}{r+k}=\binom{m+n}{m+r}$$ using combinatoric arguments.   I prefer you to answer using an analogy to a combinatoric problem or else I'll have trouble understanding.  I tried:  Let $m$ represent a group of boys and $n$ represent a group of girls. We want to form a committee with the condition that there must be $r$ more girls than boys on the committee. There's two ways of doing this. (I'm having trouble with the right-hand side.)  The left-hand side is one way of doing this. So we split the problem to different cases. One such case is where there are no boys on the committee, and so, there's $\binom{m}0\binom{n}{r+0}$ ways of forming a committee. Next, we can have 1 boy on the committee. There's $\binom{m}1\binom{n}{r+1}$ ways to do this. We repeat this process until we have $\binom{m}k\binom{n}{r+k}$ ways of forming a committee. Summing up the cases will result in the right-hand side. However, as stated before, I don't really know how to explain the right-hand side. Maybe I used the wrong analogy? Why don't all Jedi stick around as force ghosts? In many of the Star Wars movies, Jedi come back as Force ghosts.    Why don't they stick around forever, giving advice to new generations, as well as countless knowledge from thousands of years? Can I travel to Canada with valid visa on old/expired passport? I recently renewed my passport. I also have an expired passport which has my Canada visa (visitor's) valid for another three years. I have already used my Canadian visa which is multiple entry. I am planning to visit Canada this summer.  Since my valid Canadian visa is in my old/expired passport, do I need to renew/transfer my Canada visa or can I simply travel with valid visa in old passport?