I noticed some strange behaviour with lists today. layout = [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]] layout[0][0] = 0  ...results in [[0, -1, -1], [-1, -1, -1], [-1, -1, -1]] as expected. However... layout = [[-1] * 3] * 3 layout[0][0] = 0  ...results in [[0, -1, -1], [0, -1, -1], [0, -1, -1]] Am I missing something very obvious here?
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?
Retrieving HTTP status code from loaded iframe with Javascript Question:  Show that $n^2 + 3n + 5$ is not divisible by $121$, where $n$ is an integer. Clojure - Side Effects Happening Out Of Order While dabbling in Clojure I've written a very basic program to echo whatever the user types into it. However, it doesn't run in a way that I'm perceiving to be natural. Here's the code:  (defn goo []   (print "echo&gt; ")   (def resp (read-line))   (print resp) )   I would expect the code to run like this (for me typing in foo as the input to read-line):  user=&gt; (goo) echo&gt; foo foonil   But instead, the echo and read-line is switched:  user=&gt; (goo) foo echo&gt; foonil   Why does this happen? Is there a subtlety I'm missing?  EDIT: From Joe's answer, the updated correct solution is:  (defn goo []   (print "echo&gt; ")   (flush)   (def resp (read-line))   (print resp)   (flush) )   Also, the flushes aren't necessary if you use println instead of print. Why (...) doesn't spawn a new child process when run in background? Setting "checked" for a checkbox with jQuery I'd like to do something like this to tick a checkbox using jQuery:  $(".myCheckBox").checked(true);   or  $(".myCheckBox").selected(true);   Does such a thing exist? Prove that the subsequence of a convergent series with nonnegative terms converges Showing that $\frac{z^n}{1+z^{2n}}$ is real for $|z|=1$. So far, I understand that I have to look at each Jordan block. How do I prove that for a Jordan block with a value of x, $J_n(x)$, the Jordan decomposition of $(J_n(x))^2$ is $J_n(x^2)$ ? I have a feeling this will lead me to the solution. Thanks for your time. Best Practice for Forcing Garbage Collection in C# Scanner is skipping nextLine() after using next() or nextFoo()? Suppose a particle only influenced by gravity is going from point a to point b on an x,y plane. Is there an equation in which the particle takes the longest amount of time, yet still makes it to point b? I know the equation for brachistochrone is the parametric for an inverted cycloid, yet I'm not sure of the opposite. For reference, I am a high school student wanting to try this for a research project. I really only need to know whether this has already been done or not, but attempted solutions are obviously appreciated. I have a huge text file (~1GB) and sadly the text editor I use won't read such a large file.  However, if I can just split it into two or three parts I'll be fine, so, as an exercise I wanted to write a program in python to do it.    What I think I want the program to do is to find the size of a file, divide that number into parts, and for each part, read up to that point in chunks, writing to a filename.nnn output file, then read up-to the next line-break and write that, then close the output file, etc.  Obviously the last output file just copies to the end of the input file.  Can you help me with the key filesystem related parts: filesize, reading and writing in chunks and reading to a line-break?  I'll be writing this code test-first, so there's no need to give me a complete answer, unless its a one-liner ;-) The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.  Give me scenarios, other than the good old logger where it makes sense to use the singleton. When you're logged in to a Stack Exchange account, it's possible to add and remove logins (associated OpenID/OAuth accounts) without performing any form of reauthentication.  This is not a full vulnerability in itself, but it provides an extremely easy way for an attacker who's found a temporary XSS vulnerability to turn that into a permanent account hijack. An XSS exploit on its own may only provide a minute of indirect access to a user's account. But with this login configuration, the attacker could use that minute to automatically:   Add a new attacker-controlled login to the account. For example:   The XSS JavaScript would generate a random identifier, and use that to construct a login URL of the form http://hacker.example/openid/1234567. The hacker.example server would automatically authenticate the first OpenID login request made with a given identifier, allowing it to be added to the account without user interaction. All subsequent login attempts would be automatically rejected for the user. The hacker.example server would notify the operator with the account name and the generated identifier, and would allow them to login to it.  Remove all existing logins from the account. Log the user out of their account, with no way to get back in.   If this exploit were used to hijack moderator and staff accounts it could makes it more difficult to quickly respond to an attack, creating a greater opportunity for extended abuse.  This is a broader instance of the same fundamental vulnerability which was previously-reported as . That instance is a little more straightforward to fix: just ask for the password again when changing it. However, safe reauthentication with OpenID/OAuth logins is more complicated. Most users' OpenID providers will be configured to automatically re-authenticate upon request, so there would be minimal security gain from requesting that.  Instead or as well, my suggestion is that for users that have a verified email address, require an emailed confirmation link to be clicked before committing any login changes.    I'm not a real security expert, but I've just found that fellow Stack Overflow user , who is, previously described this vulnerability in his 2012 blog post :     If an attacker can add additional login accounts then they can create a persistent mechanism to get back into that Stack Overflow account at any time without needing to hijack the session. Now of course the victim can always go into their account settings and identify the presence of the new login, but it’s a question of how much damage is done before then.      How would an attacker mitigate the risk of having their newly added account removed? Just remove the victim’s original account(s) instead.      [...]      Finally, this is also a lesson for those considering using third party authentication providers. Yes, it’s great that you can farm off this work to someone who has a solid implementation, but you still have responsibility for securing the authenticated session on your site. If you choose not to, be aware of the risks because certainly we’ve seen them exploited before. Why don't self-closing script elements work? How does rooting work? Or, how do I root my device without a rooter?  Rooting instructions for Android devices that I have seen are typically of the following form:   Download Gingerbreak.apk Run Gingerbreak, click “root device” Observe that Superuser.apk has been magically installed, possibly along with busybox and other things, and enjoy your rooty goodness.   What I am wanting to know is this: how does the rooting actually happen? What does Gingerbreak do?  I understand the end result of rooting:   su is present and working Superuser.apk is installed and controls access to su Various utilities are present, provided by BusyBox (optional?)   I also think I understand the basic idea of how Gingerbreak gets started — it exploits some local privilege escalation vulnerability and uses its new-found powers to deploy Superuser and whatever else is necessary.  So, unless I am wrong in some of the understanding I laid out above, the core of thing I want to know is what the root installer does to deploy and activate Superuser. It seems that just putting Superuser.apk in the right place wouldn't be enough — how does it get allowed root access? How does it get hooked up to moderate that access for other applications?  What does Gingerbreak do post-exploit to enable and secure root access? Assessing approximate distribution of data based on a histogram Suppose I want to see whether my data is exponential based on a histogram (i.e. skewed to the right).   Depending on how I group or bin the data, I can get wildly different histograms.   One set of histograms will make is seem that the data is exponential. Another set will make it seem that data are not exponential. How do I make determining distributions from histograms well defined? Is it possible to construct an (asymmetric) encryption scheme from a signature scheme?  If the signature scheme is deterministic and allows  (e.g. ), then the answer is yes (create a forgery (m, sig); encrypt plaintexts using  with sig as the key; send m in clear to the signer along with ciphertexts, who can then compute sig and decrypt these ciphertexts) .  I am interested in similar reductions for probabilistic signature schemes.  What should the properties of a probabilistic signature scheme be so that it can be used for encryption? Can you cast a 9th level spell if your multiclass spell slots have 9th level spell slots? How is momentum conserved in this example?