I am trying to understand the background of why the following works:  def part_string(items):     if len(items) == 1:         item = items[0]         def g(obj):             return obj[item]     else:         def g(obj):             return tuple(obj[item] for item in items)     return g  my_indexes = (2,1) my_string = 'ABCDEFG' function_instance = part_string(my_indexes) print(function_instance(my_string)) # also works: print(part_string(my_indexes)(my_string))   how come I can pass my_string to function_instance object even though I already passed my_indexes attributes to part_string() when creating function_instance? why Python accepts my_string implicitly?  I guess it has something to do with the following, so more questions here: what is obj in g(obj)? can this be something other e.g. g(stuff) (like with self which is just a convention)? what if I want to pass 2 objects to function_instance? how do I refer to them in g(obj)?  Can You recommend some reading on this?
I've been reading a lot about closures and I think I understand them, but without clouding the picture for myself and others, I am hoping someone can explain closures as succinctly and clearly as possible.  I'm looking for a simple explanation that might help me understand where and why I would want to use them.
I am a beginner in learning selenium Webdriver. I am not able to understand how page object and factory models works and how it can be beneficial?    Kindly help me explain it with detailed explanation. Recovering broken or deleted NTFS partitions About two weeks ago I had a problem with my PC that my brother wrote a question about at .  I still haven't solved the problem, so my PC is unusable now.  Now I think that it would be simpler to re-install both Win7 &amp; Ubuntu than repair them, but there're some data on their partitions. I want to recover this data.  These partitions are not mountable for some reason. I don't know why.  sudo fdisk -l about the problematic partitions:     Device    Boot      Start         End      Blocks   Id  System /dev/sda1            2048     147912703    73955328   83 Linux /dev/sdb2            206848   174079999    86936576    7  HPFS/NTFS/exFAT   And in GParted:      And the error of the mount command:  Failed to mount '/dev/sdb2': Invalid argument The device '/dev/sdb2' doesn't seem to have a valid NTFS. Maybe the wrong device is used? Or the whole disk instead of a partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?   And the exact same message for /dev/sda1  How can I recover my data from those HDDs?  EDIT     I have tried to specify the type of the drive:  $ sudo mount -t ext4 /dev/sda1 /olddisk mount: wrong fs type, bad option, bad superblock on /dev/sda1,        missing codepage or helper program, or other error        In some cases useful info is found in syslog - try        dmesg | tail  or so $ sudo mount -t ntfs /dev/sdb2 /olddisk NTFS signature is missing. Failed to mount '/dev/sdb2': Invalid argument The device '/dev/sdb2' doesn't seem to have a valid NTFS. Maybe the wrong device is used? Or the whole disk instead of a partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?   EDIT     sudo ntfsfix /dev/sdb2 returns:  Mounting volume... NTFS signature is missing. FAILED Attempting to correct errors... NTFS signature is missing. FAILED Failed to startup volume: Invalid argument NTFS signature is missing. Trying the alternate boot sector Unrecoverable error Volume is corrupt. You should run chkdsk. Given a PRF $F$ , is $G(s) = F_s(1)\|F_s(2)\|\cdots \|F_s(n+1)$ a PRG? If $F$ a PRF, and we construct $G$ using $F$ in the following way:  $$G(s) = F_s(1)\|F_s(2)\|\cdots \|F_s(n+1)$$ where $|s|= n$.   Is $G$ then a PRG? If so how can I prove this? If not how can $G(s)$ be distinguished from a random $r$? And what if $n+1 &lt;$ range of $F_s$? or it could be for any $n &gt; |s|$. What happens to the energy when waves perfectly cancel each other? What happens to the energy when waves perfectly cancel each other (destructive interference)? It appears that the energy "disappear" but the law of conservation of energy states that it can't be destructed. My guess is that the kinetic energy is transformed into potential energy. Or maybe it depends on the context of the waves where do the energy goes? Can someone elaborate on that or correct me if I'm wrong? How to ask great questions As programmers we are daily faced with having to get requirements, test things out, etc.  It's practically half our job to know what questions to ask, and how to ask them to get the most concise, actionable answer possible, especially from reluctant users/managers/customers/etc.  How do you ask questions that get answers? Temporarily suspend bash_history on a given shell? Is there a way to temporarily suspend history tracking in bash, so as to enter a sort of "incognito" mode? I'm entering stuff into my terminal that I don't want recorded, sensitive financial info. A coworker and I are locked in a debate over the value of SEO keywords in the URL of a page. She wants to change all the filenames of the HTML pages of a fencing company so they look like residential-home-chicago.html, contact-chicago-contractor.html, and so on. She is convinced that because Google highlights keywords in URLs in search results, that means that putting keywords here is more valuable.  My position is that these do not improve SEO, since Google doesn't seem to give keywords in the URL any more weight than keywords in the body of the page, and . In the meantime, they make it harder for me to find the pages I want when its time to edit them, and the site as a whole looks cheap and spammy.   suggests to me that yes, keywords in URLs are useful, but not superior, and that they are more useful for human readability than search engine rankings.  I'm looking for authoritative sources that support either position, not blog articles from SEO optimization companies trying to promote themselves. What are the best practices for battery longevity? How to detect, from browser, if user is running in Remote Desktop session? What is this plastic chip packing material called? When can we speak of collinearity In linear models we need to check if a relationship exists among the explanatory variables. If they correlate too much then there is collinearity (i.e., the variables partly explain each other). I am currently just looking at the pairwise correlation between each of the explanatory variables.  Question 1: What classifies as too much correlation? For example, is a Pearson correlation of 0.5 too much?  Question 2: Can we fully determine whether there is collinearity between two variables based on the correlation coefficient or does it depend on other factors?  Question 3: Does a graphical check of the scatterplot of the two variables add anything to what the correlation coefficient indicates? What is a 'multi-part identifier' and why can't it be bound? I continually get these errors when I try to update tables based on another table. I end up rewriting the query, change the order of joins, change some groupings and then it eventually works, but I just don't quite get it.  What is a 'multi-part identifier'? When is a 'multi-part identifier' not able to be bound? What is it being bound to anyway? In what cases will this error occur? What are the best ways to prevent it?    The specific error from SQL Server 2005 is:     The multi-part identifier "..." could not be bound.   Here is an example:  UPDATE  [test].[dbo].[CompanyDetail]  SET Mnemonic = [dbBWKMigration].[dbo].[Company].[MNEMONIC],                 [Company Code] = [dbBWKMigration].[dbo].[Company].[COMPANYCODE]  WHERE [Company Name] = **[dbBWKMigration].[dbo].[Company].[COMPANYNAME]**   The actual error:     Msg 4104, Level 16, State 1, Line 3 The multi-part identifier   "dbBWKMigration.dbo.Company.COMPANYNAME" could not be bound. Alternative proof that $(a^2+b^2)/(ab+1)$ is a square when it's an integer Let $a,b$ be positive integers.  When $$k = \frac{a^2 + b^2}{ab+1}$$ is an integer, it is a square.    Proof 1: (Ngô Bảo Châu): Rearrange to get $a^2-akb+b^2-k=0$, as a quadratic in $a$ this has two values: $a$ and $kb - a = (b^2-k)/a$. (The second root is determined in two different ways from the expansion $(x-r_1)(x-r_2) = x^2 - (r_1 + r_2)x + r_1 r_2$.)  Now suppose we have $a,b$ such that $k$ is an integer but not a square, by the investigation about roots we have that the second root is a nonzero integer since $k,b,a$ are integers and $k \not = b^2$, futhermore it is positive which is easily seen from its defining equation.  WLOG assume $a \ge b$ so that the second root is strictly smaller than $a$. This leads to a decent, replacing $a$ with the second root.    Proof 2 (Don Zagier): Apply reduction theory (specifically, Sätze 1 and 2 of Section 13 of my book on quadratic fields) to the quadratic form $x^2 + kxy + y^2$, which is the unique reduced quadratic form in its equivalence class.    Note that Proof 2 is pretty much the same as Proof 1 when written out in explicit detail, but I could not read Zagier's book because I cannot read German.  I would like to know more approaches to this and other alternative proofs of this result if possible! Thanks in advance.  I would also be interested in related problems (especially easier ones of a similar nature) and texts which cover the reduction theory in English. Annotation Scaling I made a map with annotations in QGIS 3.0.  This is how it looks like in the layout view:    If I print the map as PDF, one would expect to get the PDF to be WYSIWYG, right? However, it looks like this (it's about half the size):    Is there a way to influence the the scaling of the Annoations? I already tried to play with the Scale and Magnifier in the map view. I also tried to change the Scale in the map item.   The strange thing is, I believe it worked a few days ago. But today I installed QGIS 3.0 on a new PC and it showed the same behaviour... How to remove an element from a list by index How do I remove an element from a list by index in Python?  I found the list.remove method, but say I want to remove the last element, how do I do this? It seems like the default remove searches the list, but I don't want any search to be performed. Is there any scrappable junk I should hold on to that could otherwise be used for other purposes? Power of a generator generates the group iff this power is coprime to the group order. Let $\langle g\rangle$ be a cyclic group of order $n$. Suppose $1\leq q \leq n-1$, I want to show that $g^q$ generates $\langle g\rangle$ if and only if $\gcd(n,q)=1$.  Suppose $g^q$ generates $\langle g\rangle$, then   $$ 1,g^q,g^{2q},...,g^{(n-1)q} $$  are all distinct and $g^{nq}=1$, since $n$ is the order of the group. Note that this is the lowest multiple of $q$ for which this is the case. Therefore $\operatorname{lcm}(q,n)=qn$ and it follows that $q$ and $n$ are coprime.  On the other hand, if $\gcd(q,n)=1$, then $\operatorname{lcm}(q,n)=qn$, we have $g^{nq}=1$ and hence all of  $$ 1,g^q,g^{2q},...,g^{(n-1)q} $$  are distinct again and $g^q$ is a generator.  Is my proof correct at all and is there maybe a more elegant argument? HP laptop F1-12 keys inverted with Fn I recently bought an HP laptop. I'm pleased with it, save for one thing.  All the F1-12 keys are inverted. I mean the following:  All the F-keys have a symbol on it. Normally you would press Fn + your to use it. On this laptop, it's reversed. The symbol is what you get when you press the button normally and you have to press Fn + F-key to get the usual action.  So, if I want to refresh a webpage, instead of just F5, I have to do Fn + F5  I want to change this to regular behavior. Anybody know how I can do this?  Running Win7 Home premium, 64-bit. Discrete Probability: Four dice are thrown, what's the probability that... Four dice are thrown, what's the probability that:  a) None of them fall higher than three?  b) None of them fall higher than four?  c) That four is the highest number thrown?  So for a, I wanna think about the denominator first. There are 6 possible outcomes for each dice, and we have four dice. So we're technically picking r out of n objects, aka picking 4 possible values out of 6. So the denominator/sample space should be $6^4$ right?  Now this is where I'm getting tripped up. Order technically shouldn't count, because we only care about the quadruplets that don't have a value higher than 3. I might be wrong, maybe I am, but could someone explain a bit more? My professor stated that typically in the sample space/denominator, we want order to count.   So I'm trying to think of the numerator now, so we want to find the probability that no values appear higher than 3, so some events that can occur are: $(1, 1, 2, 3), (1, 2, 2, 3), (1, 1, 1, 1)$ etc. Again, I can't see why order should count here, because if we only are concerned about what appears rather than how they appear, then we can say $(1, 1, 2, 3)$ is equal to $(1, 2, 1, 3)$? So if order does not count, and we have replacement, then does this lead the case where we use $$\binom{n-1+r}{r}$$to find out the probability?   I'm pretty sure if I can do a), I could prob do b), but if someone could maybe lead me in the right direction for c) I would appreciate that too! LaTeX minted Error I receive the following errors:  ! Package minted Error: You must invoke LaTeX with the -shell-escape flag. ! Package minted Error: You must have `pygmentize' installed to use this packag   in TexMaker Settings i wrote:     LaTeX : "/usr/texbin/latex" -interaction=nonstopmode %.tex -shell-escape      PdfLaTex: "/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode   %.tex -shell-escape   But the error still doesn't vanish ...