I come across the following python puzzle:    x=4*[[]] # x is now [[],[],[],[]]   for i in range(len(x)): x[i]+=[i];   print x;   # this returns [[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3]]   now if I do instead:    x=[[],[],[],[]];   for i in range(len(x)): x[i]+=[i];   print x;   # this returns [[0],[1],[2],[3]]   The question is, why?  I also find that if the code is changed to     x[i] = x[i] + [i]   then we have in both cases    [[0],[1],[2],[3]]     Does someone know why python behaves in this way?   Edit: the first half of my question is answered in the duplicate reference, and the second half is explained by @joriki below.
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?
Simulate a uniform distribution on a disc I was attempting to simulate injection of random points within a circle, such that any part of the circle has the same probability of having a defect.  I expected the count per area of the resulting distribution to follow a Poisson distribution if I break up the circle into equal area rectangles.    Since it requires only placing points within a circular area, I injected two uniform random distributions in polar coordinates: $R$ (radius) and $\theta$ (polar angle).  But after doing this injection, I clearly get more points in the center of the circle compared to the edge.     What would be the correct way to perform this injection across the circle such that the points are randomly distributed across the cirlce? How to insert text before the first line of a file? I've been looking around sed command to add text into a file in a specific line. This works adding text after line 1:  sed '1 a\   But I want to add it before line 1. It would be:  sed '0 a\   but I get this error: invalid usage of line address 0.  Any suggestion? Obtain the joint PDF of $\theta_{1} - \theta_{2}$ and $\theta_{1}$ where $\theta_{1}$ and $\theta_{2}$ are i.i.d $\text{Uniform}[0, 2\pi)$ I have 2 i.i.d Uniform random variables $\theta_{1}$ and $\theta_{2}$ on $[0, 2\pi)$. Here the problem pushes us to consider that all operations are made modulo $2\pi$. My question is how to obtain the joint PDF of $\theta_{1} - \theta_{2}$ and $\theta_{1}$ and then obtain the conditional PDF of $\theta_{1}$ given $\theta_{1} - \theta_{2}$??. For the second part It can be deduced from the first by writing it as the joint PDF divided by the PDF of $\theta_{1}$. But for the first part, A common idea that I saw is to derive the $\text{CDF}(x, y) = P(\theta_{1} - \theta_{2} \le x$, $\theta_{1} \le y$) and then perform derivations respect to $x$ and $y$. Is this a right approach? If yes, how to proceed with CDF especially with our uniform distribution restrictions? Automatic left and right commands I need to create a request for a web page delivered to our web sites, but I need to be able to set the host header information too.  I have tried this using HttpWebRequest, but the Header information is read only (Or at least the Host part of it is).  I need to do this because we want to perform the initial request for a page before the user can.  We have 10 web server which are load balanced, so we need to request the file from each of the web servers.    I have tried the following:  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.1.5/filename.htm"); request.Headers.Set("Host", "www.mywebsite.com"); WebResponse response = request.GetResponse();   Obviously this does not work, as I can't update the header, and I don't know if this is indeed the right way to do it. Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc I've heard that SELECT * is generally bad practice to use when writing SQL commands because it is more efficient to SELECT columns you specifically need.  If I need to SELECT every column in a table, should I use   SELECT * FROM TABLE   or   SELECT column1, colum2, column3, etc. FROM TABLE   Does the efficiency really matter in this case? I'd think SELECT * would be more optimal internally if you really need all of the data, but I'm saying this with no real understanding of database.  I'm curious to know what the best practice is in this case.  UPDATE: I probably should specify that the only situation where I would really want to do a SELECT * is when I'm selecting data from one table where I know all columns will always need to be retrieved, even when new columns are added.   Given the responses I've seen however, this still seems like a bad idea and SELECT * should never be used for a lot more technical reasons that I ever though about. I would like to label an equation with an arbitrary symbol, rather than a number, or letter.  Is this possible? INI file parsing in PowerShell I'm considering buying a subscription to Minecraft Realms (on PC) as a gift for somebody I know. Mojang doesn't have a gift option, and I don't want to spoil the surprise, so I was thinking I'd just buy it myself and give them access.   If I do this, will the recipient be able to turn around and invite their own friends? Can I grant them "admin" access to the server? Transferring domain to new host, but keeping email on old host I'm helping out a friend manage his website. Said friend has a domain, website.com, which I am transferring from his old host (OLD) to his new host (NEW), but OLD does not provide email services (or, at least, not intuitively). As a result, he wants both:   To host the website at NEW To use the email servers at OLD so he can continue using the email accounts he set up there.   The move from OLD to NEW has taken place, and I have updated the DNS records so they no longer point at ns1.old.com, and now point instead at ns1.new.com, and so on.  But having searched around a bit for the solution to the email aspect, I'm a little uncertain. I've updated the MX record at NEW to point back to ns1.OLD.com, but emails are still failing - and I'm sure the reason for this is obvious, but I'm not quite grasping what I need to do here.  As I understand it, the process ought to be as follows:   Mail sent to account@website.com website.com routes the mail to the host at NEW NEW then uses the new MX record to rout it to the servers at OLD Hey presto, the email should appear in the email inbox at account@website.com at OLD.   But this isn't happening. I get a 550 error telling me to turn on SMTP authentication, which I've read is a sure sign that I've got the MX configuration wrong. Any assistance on this would be really greatly appreciated.  tl;dr: Friend wants to move site hosting to NEW, but keep email hosting at OLD - I don't know what to do with MX and nameservers and so on to make this happen. efficient and accurate approximation of error function I am looking for the numerical approximation of error function, which must be efficient and accurate. Thanks in advance $$\mathrm{erf}(z)=\frac2{\sqrt\pi}\int_0^z  e^{-t^2} \,\mathrm dt$$ See screenshot:    Curiously, there are older badge achievement messages further down the list which display properly. How to start a background process in Python? What is the weight equation through general relativity? The gravitational force on your body, called your weight, pushes you down onto the floor. $$W=mg$$ So, what is the weight equation through general relativity? I would like to prove that : If $H$ is a subgroup of $G$ and $K$ is a subgroup of $H$, then  $$|G:K|=|G:H||H:K|$$  I appreciate any clear explanation of this. Thanks ! What is the proper way to handle data between scenes? I am developing my first 2D game in Unity and I have come across what seems an important question.  How do I handle data between scenes?  There seems to be different answers to this:   Someone mention using , while other people told me this should be used to store other things like screen brightness and so on. Someone told me that the best way was to make sure to write everything into a savegame everytime that I changed scenes, and to make sure that when the new scene loads, get the info from the savegame again. This seemed to me wasteful in performance. Was I wrong? The other solution, which is the one I have implemented so far is to have a global game object that isn't destroyed between scenes, handling all the data between scenes. So when the game starts, I load a Start Scene where this object is loaded. After this ends, it loads the first real game scene, usually a main menu.   This is my implementation:  using UnityEngine; using UnityEngine.UI; using System.Collections;  public class GameController : MonoBehaviour {      // Make global     public static GameController Instance {         get;         set;     }      void Awake () {         DontDestroyOnLoad (transform.gameObject);         Instance = this;     }      void Start() {         //Load first game scene (probably main menu)         Application.LoadLevel(2);     }      // Data persisted between scenes     public int exp = 0;     public int armor = 0;     public int weapon = 0;     //... }   This object can be handled on my other classes like this:  private GameController gameController = GameController.Instance;   While this has worked so far, it presents me with one big problem: If I want to load directly a scene, let's say for instance the final level of the game, I can't load it directly, since that scene does not contain this global game object.  Am I handling this problem the wrong way? Are there better practices for this kind of challenge? I would love to hear your opinions, thoughts and suggestions on this issue.  Thanks Root Android virtual device with Android 7.1.1 When does SQLiteOpenHelper onCreate() / onUpgrade() run? Calculating MEAN and STANDARD DEVIATION confussed Count the number of fish caught in total if we are given the number of fishermen who caught at least $n$ fish. Some fishermen caught some fish. No one caught more than 20 fish. $a_i$ is the number of fishermen who caught at least $i$ fish. How many fish were caught?   So my guess is that the number of fish caught has to be $$ a_1+a_2+\ldots + a_{20}$$  I reason that if a fisher man caught $n$ fish then he will appear in the tally $n$ times.   Is this logic correct?