Say, I have this list: ['1', '1', '0', '1', '1', '1', '0', '0', '0', '0', '1', '0'] My expected output: [['1', '1', '0', '1'], ['1', '1', '0', '0'], ['0', '0', '1', '0']] I got the expected output this way: from collections import deque as de a = '110111000010' a = list(a) que = de(a) a = [] l = [] n = 0 while que:     item = que.popleft()     l.append(item)     n += 1     if n == 4:         a.append(l)         n = 0         l = [] print(a)  I wanted to know is there a more efficient and simpler way to achieve this which can be described as elegant, understandable and most importantly pythonic.
I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list fills up, add it to the first list and empty the second list for the next round of data, but this is potentially extremely expensive.  I was wondering if anyone had a good solution to this for lists of any length, e.g. using generators.  I was looking for something useful in itertools but I couldn't find anything obviously useful. Might've missed it, though.  Related question:
Calculating $\sum_{n=1}^\infty\frac{1}{(n-1)!(n+1)}$ I want to calculate the sum:$$\sum_{n=1}^\infty\frac{1}{(n-1)!(n+1)}=$$  $$\sum_{n=1}^\infty\frac{n}{(n+1)!}=$$ $$\sum_{n=1}^\infty\frac{n+1-1}{(n+1)!}=$$ $$\sum_{n=1}^\infty\frac{n+1}{(n+1)!}-\sum_{n=1}^\infty\frac{1}{(n+1)!}=$$ $$\sum_{n=1}^\infty\frac{1}{n!}-\sum_{n=1}^\infty\frac{1}{(n+1)!}.$$  I know that $$\sum_{n=0}^\infty\frac{1}{n!}=e$$  so $$\sum_{n=1}^\infty\frac{1}{n!}=\sum_{n=0}^\infty\frac{1}{n!}-1=e-1$$  But, what can I do for $$\sum_{n=1}^\infty\frac{1}{(n+1)!}$$ ?  Am I allowed to start a sum for $n=-1$ ? How can I bring to a something similar to $$\sum_{n=0}^\infty\frac{1}{n!}$$? Fundamental group of the torus I'm trying to get my head round the following calculation of the fundamental group of the torus, using Seifert Van-Kampen (I know it's easier to do this by considering covering spaces, but I'm trying to learn the Seifert Van-Kampen method).   Consider the torus $T$ as the unit square in $\mathbb R^2$ with opposite edges identified. Let $A$ be an open disc (say of radius $1/4$ about the origin), and $\overline{A}$ be it's closure. Let $B$ be complement of $A$, so that $A \cap B = S^1$. Then we have $T = A \cup B$ where $A$ and $B$ are a neighbourhood deformation retract pair, so we can use Van Kampen. It is clear that $\pi_1(A) = \{e \}$ and $\pi_1(A \cap B) = \mathbb Z$. So we need to find $\pi_1(B)$. Observe that $B$ deformation retracts onto the boundary of the square which, after identification, is homeomorphic to $S^1 \vee S^1$; in this way we see that $B$ and $S^1 \vee S^1$ are homotopy equivalent (inclusion in one direction, the retraction in another), and so $\pi(S^1 \vee S^1) = F_2$ (which can be calculated by Van Kampen, or by using the theory of covering spaces). So, by Van Kampen, $\pi_1(T) \cong F_2 *_{\mathbb Z} \{e\}$. This is the quotient of $F_2$ by the normal closure of the image of $l_* : \pi_1(A \cap B) \to \pi_1(B)$ (where $l_*$ is the homomorphism induced from the inclusion map $l : A \cap B \hookrightarrow B$). The following is causing me confusion: The generator of $\pi_1(A \cap B)$ is homotopic in $B$ to a loop of the form $u.v.\overline{u}.\overline{v}$, where $u$ and $v$ represent the two generators of $F_2$. So $\pi_1(T) \cong \langle a,b ; aba^{-1}b^{-1} \rangle$, the free abelian group on two generators.  Any explanation or geometric intuition would be really appreciated. Thanks Why are my textures pink? Is fractional scaling ( ) available in 18.04 LTS yet? I am waiting until this is available before I install. What's the fastest way to count the number of keys/properties of an object?  It it possible to do this without iterating over the object?  i.e. without doing  var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) count++;   (Firefox did provide a magic __count__ property, but this was removed somewhere around version 4.) I'm trying to install a Matlab R2011a launcher for Unity in Ubuntu 12.04. I've tried  (although I know it's for 11.10 and mentions that even 11.10 is an unsupported OS for Matlab R2011a) but without any satisfactory solution.  This is my launcher file, /usr/share/applications/matlab.desktop:  #!/usr/bin/env xdg-open [Desktop Entry] Type=Application Icon=/usr/share/icons/matlab.png Name=MATLAB R2011a Comment=Start MATLAB - The Language of Technical Computing Exec=matlab -desktop Categories=Development;   I open the dash panel and search for "matlab". This launcher is found among applications. I click it, and Matlab's splash screen shows up, but when it disappears the program doesn't start. (I've verified with htop that no matlab-processes are running in the background either.)  If I add  Terminal=true   to the launcher file, the program starts OK, and opens a terminal as well as Matlab. However, both the terminal and Matlab itself show up in the Launcher area, with the Matlab icon, so it looks like I have two Matlab instances running when really it's only one. (Actually, they show up as two different programs, and not just two instances of the same - the icons are independent, not grouped together.)  This is definitely not optimal. I had hoped to create a launcher I can lock to the launcher area, and then that same icon will be the icon for the active Matlab instance when the program is running.  How do I create a launcher for Matlab that works as expected?  Update: I was apparently a bit unclear on my symptoms, I'll try to clarify a little. I've also tried some suggestions from the answers, and further investigated what happens. My current setup (a launcher file with Terminal=true and Exec=matlab -desktop -nosplash &amp;) renders the following behavior:   I open Dash by pressing the Windows key on my laptop, and search for "matlab". It finds the launcher named "MATLAB R2011a". I click it. A terminal window opens, using the icon I referred to in the launcher file. Almost immediately, MATLAB's splash screen also opens, using the same icon (and thus being grouped with the terminal window in the launcher). The splash screen disappears and, so does one of the icons in the launcher. The MATLAB desktop environment opens, using a different version of the icon which is displayed next to the icon for the terminal window (not grouped with it).   I can lock the terminal window's icon to the launcher and successfully start MATLAB by clicking it, but it doesn't feel optimal that I start the program with one icon, and switch to it with another. I've also tried the following:   Exec without the ampersand &amp; in the launcher command, but it didn't make a difference. Executing matlab -nosplash manually from a terminal still shows the splash screen. (What, then, does the nosplash option really do?) How can I integrate $$\ln \left( x+\sqrt{1+x^2} \right) $$   The problem is from IA Maron Calculus, Problem 4.3.17. The problem is under the heading 'Integration by parts'. I have tried it, but it just leads to 2 unsolvable integrals Natural log approximation I've got an equation that contains   $$x^p - 1$$   $x$ is any positive number (such as 2) and $p$ is a small positive number close to 0 (such as 0.001).  For some reason (that I may have known in High School), this can be approximated by   $$\ln(x) \times p$$  Can anyone explain why this approximation works?  Does it have something to do with approximating a natural log with a series? "Dark L" is "L" at the end of the word or after a vowel sound. Example: ball, pull.  "Light L" is "L" at the beginning or before a vowel sound. Example: light, love.  There are 4 explanations of how to pronounce "dark L":   1st explanation: the tongue tip must contact the ridge right behind the upper teeth. 2nd explanation: before the tongue tip must contact the ridge right behind the upper teeth, you must curl the tongue and make sound like /r/ before make the /l/ as in the 1st explanation. 3rd explanation: just put the tongue between upper and lower teeth is enough to make the dark L 4th explanation: the tongue tip must contact the ridge right behind the upper teeth &amp; the back of the tongue raises up (a British teacher teaches that).   see this vid:  and  for more info  So what is the correct way to make the "dark L"? Best way to clone an installation (copying to identical hardware) Kind-of like  but slightly different (I think), in that I have 6 identical Acer Aspire Revo R3610 machines. One is (almost) configured to my requirements - when I'm done preparing it I'd like to make the other 5 machines absolutely the same. I'm very new to Ubuntu, what's the most straightforward (easiest) way of doing this?  The machines are going to live on different networks if that might otherwise be a problem (eg with Windows you can clone disks but you then have to make registry changes afterwards if they're going to run on the same network etc). The hardware in all 6 machines is, I stress, the same!  How can I efficiently clone one source image on to these identical machines?  Please restrict one software/solution per answer Temporarily change language for terminal messages/warnings/errors Messages in my terminal are displayed using Russian language by default, which is my native one.  For just a moment I want them to be in English (eg. to paste in forums), then switch back to the default language.  How can I do the switch and switch back using bash? Define $\mathcal N$  $\mathcal N (A):=\mathcal P(A)\setminus\{\varnothing\}$  Does $\mathcal N$ has a special name and standard notation? Can't access select https sites on Linux over PPPoE My internet connection used to be a direct LAN connection to my provider. Back then, everything would load fine on both Windows and Ubuntu (dual boot). However, a while ago they started needing me to dial (PPPoE) using a username and password. Gateway, subnet mask, IP, DNS servers all stayed the same. But since then, I haven't been able to browse certain websites on Ubuntu, even though there have been no such issues on Windows. Some example websites are -  (although share.ovi.com loads fine, and nokia.com loads fine),  (works on Chrome(ium) and Opera but not on Firefox (both 3.6 and 4)) Mozilla  and other random websites.  Some of the websites that don't load show timeout messages and for some websites (like the moz addons one), the browser will keep trying to load without an end (I've left it like that even for hours but not noticed anything different happen).  I have tried changing the DNS servers to public ones. I have even tried booting from a Fedora LiveCD and then changing the DNS to those (and even to the ones of OpenDNS), but the exact same thing happens. What could be inherently wrong with some config within Linux itself that is causing this problem?  Does anyone know why this is happening and how it can be fixed?  Note: This question has been  on SU, but not gotten any responses.  Update: Just saw  that someone else was having similar problem and solved it by putting a NetworkManager.conf file in /etc/NetworkManager. What needs to be in that file? Coming from a programming background, where should I start to learn web design? I'm a web developer mainly working in front end developing. My main fields are HTML5, CSS3 and Flash ActionScript 3.0.  Here in Iran, teamwork means nothing for most of the people, but I think it's the most important aspect of our work, especially in web design.   I have poor skills in graphic design and UI design. I always have to work with graphic designers for my websites. They are usually good and skilled designers. But they are all print designers and unfortunately they know nothing about the web and designing for it.  For example, one of the designers that I work with most of the time is a great designer and he won a couple awards for his logo and poster designs. However, he knows nothing about the web and most of my time is spent explaining to him how things work on the web, i.e. in what size he should work, using pixels instead of centimeters, and so on... After all he is a print designer, not a web designer. They often think everything is static and constant, not in motion.  So the best way to work around this is to improve my skills in graphical designing. I just want to be able to design good layouts, make good color selections, and etc for my websites. I do not want to design illustrations and do heavy graphical works. Just design websites with no Photoshop illustrations like posters and etc.  What do you do for your graphic works, and if you do them yourself, which books or references do you suggest I read? Where should I start? I thought this would be a simple question, but I'm having trouble figuring it out. Not a homework assignment btw. I am a physics student and am just genuinely interested in physics problems involving math, which would be all of them.  So lets say we drop an object from a height, $R+r$, it falls toward earth. This height, $R+r$, is far enough away that the $g$ it experiences is a fraction of $g$ at sea-level. Let's just say that air resistance is negligible, and it wouldn't be that complicated to just integrate from $0$ velocity to the terminal velocity piece wise and deal with the rest of it later.  So the key here is that acceleration is changing with time. I thought I could simplify this by saying it changes with distance, and it has nothing to do with time, but this didn't really help, my guess is that maybe time is important (doh).  I tried integrating acceleration with time, and ended up nowhere. I tried integrating $a=GM/R^2$ with respect to $R$ from $R+r$ to $R$ and ended up with a negative function.  I saw somewhere someone tried to expand with taylor series, they even have something similar on hyperphysics, but I can't figure out how to obtain the polynomials that precede the variables.    This is the hyperphysics site where they use polynomials to find the distance.   Maybe I can't solve this because I haven't taken a course in differential equations yet. What I want to know is how to calculate the distance at any time. "Unanswered" question sort order on profile pages To help users keep track of (and hopefully get answers to) unanswered questions, it would be useful to have an "unanswered" sort order on a user's profile page.  It would order the list of questions with unanswered questions first.   This would be in addition to the "recent," "views," "newest," and "votes" sort orders. How to align content of a div to the bottom How to I see the number of sessions in the Google Analytics aquisition overview main graph? Under Acquisition --> Overview, a graph appears around middle of the screen titled "sessions".  It is actually showing the total number of users over a particular time period, I'd like it to show the number of sessions and not users on the blue graph.     How do I change it? How to get only filename using sed How can I get only the filename using sed? I've this  out_file=$(echo $in_file|sed "s/\(.*\.\).*/\1mp4/g")   But I get the path too /root/video.mp4, and I want only video.mp4. I need to run a bash script at boot-time as superuser in Xubuntu. I don't know where to start. I have to do something described in a Arch Linux guide. That guide says exactly:     Add following at the end of the file : /etc/rc.sysinit   # Do my action /etc/rc.d/do_my_action  /bin/dmesg &gt;| /var/log/dmesg.log   But I do not have /etc/rc.sysinit and /etc/rc.d/ in Xubuntu. I'm sure there are equivalent ones, right?