Python string formatting with 'n' number of digits (when using keys) Python 2.7 To have specific number of digits in string formatting, I am aware that it can be done in this way:  In [18]: hours = 01  In [19]: "%.2d" %(hours) Out[19]: '01'  In [20]: "%.2f" %(hours) Out[20]: '1.00'   But my case is a bit different. I am using specific keys to denote the values, for example:  for filename in os.listdir('/home/user/zphot_01/')   Here I want to have different values for the '01', i.e.   for filename in os.listdir('/home/user/zphot_{value1}/'.format(value1=some_number):   When I use the above method with some_number = 01, it does not take into account the 0 and so my folder is not recognised.   EDIT:  Most of the answers are for only one value, however, I want to have more than one key value, i.e.:  for filename in os.listdir('/home/user/zphot_{value1}/zphot_{value2}'.format(value1=some_number1,value2=some_number2)).
How to pad zeroes to a string? What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?
DataView.Sort - more than just asc/desc (need custom sort) booting windows 10 spends too long GoogleApiClient.isConnected() return always false When are attributive nouns plural? Sorry for the title, it is not very evident and intuitive but I really do not how to tell it better...  Well, you know, several times, or better, many times, we use this form:  If I want to say:      "development of special weapons was   the first point in Hitler's   program..."   I will say this (a better form):      "special weapon development was..."   OK...  is it      "special weapon development"   or      "special weapons development" (note   the plural...)   what's the grammar rule in order to understand how to use this very used form? How exactly does a "random effects model" in econometrics relate to mixed models outside of econometrics? I used to think that "random effects model" in econometrics corresponds to a "mixed model with random intercept" outside of econometrics, but now I am not sure. Does it?  Econometrics uses terms like "fixed effects" and "random effects" somewhat differently from the literature on mixed models, and this causes a notorious confusion. Let us consider a simple situation where $y$ linearly depends on $x$ but with a different intercept in different groups of measurements:  $$y_{it} = \beta x_{it} + u_i + \epsilon_{it}.$$  Here each unit/group $i$ is observed at different timepoints $t$. Econometricians call it "panel data".    In mixed models terminology, we can treat $u_i$ as  a fixed effect or as a random effect (in this case, it's random intercept). Treating it as fixed means fitting $\hat \beta$ and $\hat u_i$ to minimize squared error (i.e. running OLS regression with dummy group variables). Treating it as random means that we additionally assume that $u_i\sim\mathcal N(u_0,\sigma^2_u)$ and use maximum likelihood to fit $u_0$ and $\sigma^2_u$ instead of fitting each $u_i$ on its own. This leads to the "partial pooling" effect, where the estimates $\hat u_i$ get shrunk toward their mean $\hat u_0$.  R formula when treating group as fixed:    y ~ x + group R formula when treating group as random:   y ~ x + (1|group)  In econometrics terminology, we can treat this whole model as a fixed effects model or as a random effects model. The first option is equivalent to the fixed effect above (but econometrics has its own way of estimating $\beta$ in this case, called "within" estimator). I used to think that the second option is equivalent to the random effect above; e.g. @JiebiaoWang in his highly upvoted answer to  says that      In econometrics, the random-effects model may only refer to random intercept model as in biostatistics    Okay --- let us test if this understanding is correct. Here is some random data generated by @ChristophHanck in his answer to  (I put  for those who do not use R):    @Christoph does two fits using econometrics approaches:    fe &lt;- plm(stackY~stackX, data = paneldata, model = "within") re &lt;- plm(stackY~stackX, data = paneldata, model = "random")   The first one yields the estimate of beta equal to -1.0451, the second one 0.77031 (yes, positive!). I tried to reproduce it with lm and lmer:  l1 = lm(stackY ~ stackX + as.factor(unit), data = paneldata) l2 = lmer(stackY ~ stackX + (1|as.factor(unit)), data = paneldata)   The first one yields -1.045 in perfect agreement with the within estimator above. Cool. But the second yields -1.026, which is miles away from the random effects estimator. Heh? What is going on? In fact, what is  plm even doing, when called with model = "random"?  Whatever it is doing, can one somehow understand it via the mixed models perspective?  And what is the intuition behind whatever it is doing? I read in a couple of econometrics places that random effects estimator is a weighted average between the fixed effects estimator and the "between" estimator which is more or less regression slope if we do not include group identity in the model at all (this estimate is strongly positive in this case, around 4.) E.g. @Andy :     The random effects estimator then uses a matrix weighted average of the within and between variation of your data. [...] This makes random effects more efficient[.]   Why? Why would we want this weighted average? And in particular, why would we want it instead of running a mixed model? Simple combination/probability question based on string-length and possible-characters Assuming "complete randomness" and given a string with a length of 20 characters where each character may be one of 62 possible characters:    What are the total number of combinations possible? (Guessing 20 to the power of 62.)  Also, if new strings are randomly selected one after another and added to a list of strings selected so far, how many strings must be selected before the chance of selecting a string that has already been selected is below 1-in-100000 ($10^{-5}$)?   Note: 62 comes from: numeric digits (0-9), uppercase letters (A-Z), and lowercase letters (a-z). Space $\mathcal{L}^p(X, \Sigma, \mu)$ is separable iff $(\Sigma, \rho_\Delta)$ is separable Let's consider the space $\mathcal{L}^p(X, \Sigma, \mu)$ of all functions $f\colon X \to \mathbb{R}$ (or $\mathbb{C}$) for which: $$ \int\limits_X|f|^p \mu(dx) &lt; \infty. $$ Here $X$ is a metric space, $\Sigma\subset 2^X$ — sigma-algebra on $X$ and $\mu$ — is the measure on $\Sigma$. As usual, functions that are equal almost everywhere considered to be equivalent, so technically we are dealing with classes $$[f]=\{g\in \mathcal{L}^\infty(X,\Sigma, \mu) \colon \mu \{x\in X\colon f(x)\neq g(x)\}=0\}.$$ This space is endowed with integral metric $$\rho_p(f,g)=\left(\int\limits_X|f-g|^p \mu(dx)\right)^{1/p}$$  The statement is that space $\mathcal{L}^p(X, \Sigma, \mu)$ is separable iff $(\Sigma, \rho_\Delta)$ is separable, where $\forall A,B\in\Sigma$ $$\rho_\Delta(A,B)=\mu(A\Delta B)$$ Here, again, we consider $A\in \Sigma$ as a class $[A]=\{A'\in\Sigma\colon \mu(A\Delta A')=0\}$ to have the identity of indiscernibles.  How do one prove the statement? Draw integers independently & uniformly at random from 1 to $N$ using fair d6? I wish to draw integers from 1 to some specific $N$ by rolling some number of fair six-sided dice (d6). A good answer will explain why its method produces uniform and independent integers.  As an illustrative example, it would be helpful to explain how a solution works for the case of $N=150$.  Furthermore, I wish for the procedure to be as efficient as possible: roll the least number of d6 on average for each number generated.  Conversions from  to decimal are permissible.    . Consecutive/Rolling sums in a vector in R Prove that $V = V_1 \oplus V_2$ in the following Let $V$ be a vector space over $\mathbb{C}$ such that $T^2=1_V$. Define  $V_1 = \left\{v\in V |\ T(v) = v \right\}$,  $\ V_2 = \left\{v\in V |\ T(v) = -v\right\}$  prove that $V = V_1 \oplus V_2$  For start, I've shown that $V_1\ ,V2$ are subspace of $V$. However, I'm stuck trying to show that $\forall \ v\in V,\ v = v_1 + v_2$ where $v_1 \in V1, v_2 \in V_2$.  I know at some point I have to make use of  $T^2=1_V$, but cant figure out how. Any help or insight is deeply appreciated. Why would a spinning space station create a centrifugal force on an astronaut rather than simply spinning around him/her? We often see films with spinning space station that create  by having the astronauts pulled outwards by centrifugal force.  I'd like to know if this would really happen, and if so, why is the following scenario not true:   Take an astronaut in open space. He doesn't move. Put a big open spinning cylinder around him - surely he still doesn't move. Close the cylinder. I still see no reason for him to be pulled outwards. I installed an alpha or beta, am I up to date with the final release if I keep upgrading? I installed an Ubuntu alpha or beta and have been keeping it up to date.   So, Should I presume that my system has automatically updated to the next alpha or beta, and will be running the official release when it's finished? How to typeset asymmetrical confidence level limits / uncertainties? Sorting citations using \cites command in biblatex I am using biblatex for citations and bibliography. Now I often have lists of multiple citations, for which biblatex has the \cites command. Now I can get citations to automatically sort if I don't want page numbers, but I cannot get it right with page numbers.  What I want is all citation ordered chronological (oldest first). Is this possible, or must I just do this by hand?  Here is an example.  \documentclass[11pt,oneside]{memoir}  \usepackage[     style=authortitle,     useprefix=false,     maxnames=2,     firstinits=true,     sortcites=true,     uniquename=init,     abbreviate=true,     backend=biber,     sorting=ynt ]{biblatex}  \begin{filecontents}{jobname.bib} @book{tom1,   author = {Author, A.},   year = {2001},   title = {This book is from 2001},   shorttitle = {2001}, } @book{tom2,   author = {Author, A.},   year = {1999},   title = {This book is from 1999},   shorttitle = {1999}, } \end{filecontents}  \addbibresource{jobname.bib}   \begin{document} This one is corrent.\footnote{\Cites{tom1,tom2}.} This one is corrent.\footnote{\Cite{tom1,tom2}.}   This one is incorrent.\footnote{\Cites{tom1}{tom2}.} This one is incorrent.\footnote{\Cites[1]{tom1}[12]{tom2}.} \end{document} Reading order for Dragonlance? Tense change: previous actions on something that's currently true I'm describing a situation that happened in the past. To explain it, I want to use a description that is both true now and true when the situation happened.  Specifically, I want something like:     She touched me where my neck met my collarbone.   Since my neck is still attached to my collarbone (thankfully), I'm wondering if I shouldn't use the present tense here instead:     She touched me where my neck meets my collarbone.   Which is preferable, and why? Is storing passwords hashed with the email more secure than without? Can you dispel a magic effect you can't perceive? Discussions about Dispel Magic seem to imply that as long as you can perceive a magic effect in range of the spell, you can try and dispel it.   See  and  from @Miniman:      knowing where it is means that you know where it is. This allows you to use spells like Dispel Magic to remove its invisibility.   But what if you can't perceive it?  Two scenarios come in mind:   In combat, an evil wizard casts Invisibility on himself, walks away from the fray and uses the hide action on his next turn. Since PCs know/assume/deduce he's invisible and certainly in range of the spell, can one use Dispel Magic to end the spell? PCs enter a 80'&times;80' room. Can one declare: "I dispel any Invisibility spell in range", thus revealing one (the closest?) invisible enemy in the room?   What's enough to enable a caster to cast Dispel Magic on a magic effect:    perceiving (seeing, hearing, smelling, etc.) it? knowing/assuming/deducing it's there? or merely suspect/predict it? Is there a way to enable/disable a wireless network interface via the command line (so I can put it in a bat file)?  When I'm in the office I use a wired connection, but Windows still occasionally bugs me about my wireless connection not being connected (even though I turned off the option for notifying me when there's no connectivity).  I'm guessing the only way to stop it from bugging me is to disable the interface, but I'd rather not have to go into the network settings every time I need to do so.  I'd like to set up a bat file or a shortcut that I can use to enable/disable the wireless (preferably a single one that toggles the current state), and then just set up a keyboard shortcut for that.  I just have no idea how to do so from the command line. How to get an enum value from a string value in Java? Say I have an enum which is just public enum Blah {     A, B, C, D }  and I would like to find the enum value of a string, for example &quot;A&quot; which would be Blah.A. How would it be possible to do this? Is the  the method I need? If so, how would I use this?