Printing a list of integers in groups of X in Python I have a list consisting of 150 integers, each one ranging from 1 to 80. I want to print the list with the following format:   x01, x02, x03, x04, x05,  x06, x07, x08, x09, x10, x11, x12, x13, x14, x15,  x16, x17, x18, x19, x20,  ... ... ...   In other words I want to print the numbers in groups of 5. How do I do that?
What is the most "pythonic" way to iterate over a list in chunks? I have a Python script which takes as input a list of integers, which I need to work with four integers at a time.  Unfortunately, I don't have control of the input, or I'd have it passed in as a list of four-element tuples.  Currently, I'm iterating over it this way: for i in range(0, len(ints), 4):     # dummy op for example code     foo += ints[i] * ints[i + 1] + ints[i + 2] * ints[i + 3]  It looks a lot like &quot;C-think&quot;, though, which makes me suspect there's a more pythonic way of dealing with this situation.  The list is discarded after iterating, so it needn't be preserved.  Perhaps something like this would be better? while ints:     foo += ints[0] * ints[1] + ints[2] * ints[3]     ints[0:4] = []  Still doesn't quite &quot;feel&quot; right, though.  :-/ Related question:
How do you challenge the closing of one of your questions? How can I get around giving my mobile phone number to Google? How to check if a service is running on Android? How do I check if a background service is running?  I want an Android activity that toggles the state of the service -- it lets me turn it on if it is off and off if it is on. I tried using integration by parts twice, the same way we do for  $\int \sin {(\sqrt{x})}$ but in the second integral, I'm not getting an expression that is equal to  $\int x\sin {(\sqrt{x})}$.  I let $\sqrt x = t$ thus, $$\int t^2 \cdot \sin({t})\cdot 2t dt =  2\int t^3\sin(t)dt = 2[(-\cos(t)\cdot t^3 + \int 3t^2\cos(t))] = 2[-\cos(t)\cdot t^3+(\sin(t)\cdot 3t^3 - \int 6t \cdot \sin(t))]]$$  which I can't find useful. "ImportError: No module named _struct" configuring python-minimal When I run sudo apt-get upgrade, the dpkg error appears and interupts the process.  Error details:  Setting up python-minimal (2.7.3-0ubuntu7.1) ... Traceback (most recent call last):   File "/usr/local/lib/python2.7/runpy.py", line 162, in _run_module_as_main     "__main__", fname, loader, pkg_name)   File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code     exec code in run_globals   File "/usr/local/lib/python2.7/compileall.py", line 16, in &lt;module&gt;     import struct   File "/usr/local/lib/python2.7/struct.py", line 1, in &lt;module&gt;     from _struct import * ImportError: No module named _struct dpkg: error processing python-minimal (--configure):  subprocess installed post-installation script returned error exit status 255 dpkg: dependency problems prevent configuration of python:  python depends on python-minimal (= 2.7.3-0ubuntu7.1); however:   Package python-minimal is not configured yet.   And this problem leads to a series of dependency problems when processing the following packages:    python  gwibber-service  libgwibber3  libgwibber-gtk3  gwibber  gwibber-service-facebook  gwibber-service-identica  gwibber-service-twitter  python-all  python-dev  python-all-dev  python-apt  python-problem-report  python-apport  python-libxml2  unity-lens-gwibber  unity-scope-video-remote   Finally, nothing I can do for this problem. And several days later, the root directory is full and I even could not uninstall any software because of this problem. How to find and return a duplicate value in array Characterizing non-constant entire functions with modulus $1$ on the unit circle Is there a characterization of the nonconstant entire functions $f$ that satisfy $|f(z)|=1$ for all $|z|=1$?   Clearly, $f(z)=z^n$ works for all $n$. Also, it's not difficult to show that if $f$ is such an entire function, then $f$ must vanish somewhere inside the unit disk. What else can be said about those functions?  Thank you. Improve alignment of "Learn more" button in "Newest badge" popup The popup when you click on your newest badge in your user profile has a &quot;Learn more&quot; button, but its alignment is suboptimal; it's too close to the top of its container:  It looks better with a 4px top margin: How to add percent sign to NSString Prove that $\left (\frac{a^2 + b^2 +c^2}{a+b+c} \right) ^ {(a+b+c)} > a^a b^b c^c$ Prove that $\left (\dfrac{a^2 + b^2 +c^2}{a+b+c} \right) ^ {(a+b+c)} &gt; a^a b^b c^c$ if $a$, $b$ and $c$ are distinct natural numbers.  Is it possible using induction? Switching back to last *used* tab on Chrome When you suggest an edit to a post and view the post while it's pending, . But as noted in the , this linking hasn't been implemented for tag wikis/excerpts yet, partly because there are potentially two links to include and the wording is not entirely obvious, and partly because they're orders of magnitude less common.  Here's my suggested wording for the three cases.   Tag wiki excerpt only     Thanks for your edit!   This edit will be visible only to you until it is .  Tag wiki only     Thanks for your edit!   This edit will be visible only to you until it is .  Both     Thanks for your edit!   These edits will be visible only to you until they are peer reviewed (, ).        I can't directly address the prioritization of tag wiki edits, but I'd appreciate the corresponding  or  mark, at least. Convert stored procedure result to model object RGB and CMYK: Why both? Any of you who have at least little experience with graphic design software, photography or professional printing, must have -almost undoubtedly- have gone through this: 'the struggle' of RGB and CMYK colour spaces.  Now, there are many questions regarding matters of 'which should I choose', 'what is what' and converting problems, but that's not really what I'm after here.  As a graphic designer with only a couple of years of experience, I still have this struggle from time, and find the whole CMYK/RGB choosing/converting/saving situation quite confusing, to say the least. I do know that RGB is meant for digital end purposes, and CMYK is suitable for printing.  I have always been wondering about the neccesity of this whole thing. So, my question is: why are there these two colour profiles, instead of just having one?   Wouldn't it be a lot easier if printers or software could convert any RGB file to a CMYK printing document instead? I'm pretty sure it does already exist, by the way, because printing an RGB file sometimes simply prints the right colours for me. Alas, not always (doesn't seem to be related to the printer of software I print from).    I have gone trough some RGB vs. CMYK-related questions and found this, a.o., (), an answer of user DKuntz2 (thanks DKuntz2):     RGB is a light-based theory. All colors begin with black "darkness",   to which different color "lights" are added to produce visible colors.   RGB "maxes" at white, which is the equivalent of having all "lights"   on at full brightness (red, green, blue).      CMYK is a color-based theory. All colors start with white "paper", to   which different color "inks" are added to produce output colors. CMYK   "maxes" at black, at which point all "inks" are applied at 100% (cyan,   magenta, yellow, black).   Not sure if this is entirely right, though, because some people disagreed with DKuntz2:     I disagree. With RGB you start with black - the absence of light; with   CMYK you start with white paper.   – e100  Although this does clarify the differences fairly well, I still don't see the point of the two colour profiles(/spaces)    Side question: What happens when you work in an RGB document in photoshop, then press ctrl+y? Photoshop says the document is RGB/8/CMYK, but it can't be both. Right?  EDIT:  Big thanks for the answers, the (current) three below are very informative and interesting. I understand the whole thing a bit better, although it's all very complicated and in-depth to me. Especially when I read about terms like colour models, colour profiles, colour spaces, colour spectra and gamut all one after another.  As much as I would like to accept an answer as the desired one, I feel that my question in the core isn't fully answered yet. What I would really like to emphasize is what I asked about earlier: Wouldn't it be a lot easier if printers or software could convert any RGB file to a CMYK printing document instead?. As Alan Gilbertson explained, the reason is - if I understand correctly - basically a 'lost-in-translation' thing that makes the conversion not 100% accurate, and the colours to possibly be a bit distorted.  However, I still don't see how the solution cannot be an automated conversion done by a printer. Should be possible with modern technology; if you can convert RGB to CMYK in Photoshop, why can't a printer do the exact same for you? As was also said in the answers, the slightest differences in colours and colour spaces, can not be seen by the human eye. And that's what it all comes down to: what we want to see. Be it on a screen or on a sheet of paper.  The fact that this question has three very long answers, or even moreso the fact that there are so many questions about these two colour models (I now know the right term, yay) kind of proves that this is way more complicated than it should be. Actual memory usage of a process The following are the memory usage of mysql and apache respectively on my server. As per the output of pmap say, mysql is using about 379M and apache is using 277M.   [root@server ~]# pmap 10436 | grep total  total           379564K  [root@server ~]# pmap 10515 | grep total  total           277588K   Comparing this with the output of top, I see the values are almost matching.    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND 10515 apache    20   0  271m  32m 3132 S  0.0  6.6   0:00.73 /usr/sbin/httpd 10436 mysql     20   0  370m  21m 6188 S  0.0  4.3   0:06.07 /usr/libexec/mysqld --basedir=....   Now these values definitely are not the current memory usage of those two processes, since if it were it would've exceeded the 512M ram on my system and I understand the fact that these are the size of the pages assigned to these two processes and not really the size of the memory actively used by them. Now, when we use pmap -x, I see an extra coloumn Dirty which shows far less memory usage for the process. As seen in the example show below, the Dirty coloumn shows 15M as opposed to 379M in the first coloumn. My question is: Is the value under coloumn Dirty is the 'real' amount of memory actively used by that process? If its not, then how can we find out the real memory usage of a process? Not ps and top for the same reasons above. Do we have anything under /proc that will give this info?  [root@server ~]# pmap -x 10436 | grep total total kB          379564   21528   15340 [root@server ~]#   [root@server ~]# free -m              total       used       free     shared    buffers     cached Mem:           489        447         41          0         52        214 -/+ buffers/cache:        180        308 Swap:         1023          0       1023 [root@server ~]# What does "65" mean? K-2SO beats up the troopers easily. Up in the sky, the bombers are preparing to attack. Just as they start the attack run, TIE fighters come in from the shield and swarm the rebel fleet.  JON VANDER (GOLD LEADER): Red Leader, this is Gold Leader, we’re starting our attack run on the  shield gate. Keep it tight and watch out for those towers. GOLD PILOT: More fighters. Form up, at 65.  What does &quot;65&quot; mean? PCA and proportion of variance explained When is assembly faster than C? One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular.  However, I've also heard it stated many times that although that's not entirely false, the cases where assembler can actually be used to generate more performant code are both extremely rare and require expert knowledge of and experience with assembly.    This question doesn't even get into the fact that assembler instructions will be machine-specific and non-portable, or any of the other aspects of assembler.  There are plenty of good reasons for knowing assembly besides this one, of course, but this is meant to be a specific question soliciting examples and data, not an extended discourse on assembler versus higher-level languages.  Can anyone provide some specific examples of cases where assembly will be faster than well-written C code using a modern compiler, and can you support that claim with profiling evidence?  I am pretty confident these cases exist, but I really want to know exactly how esoteric these cases are, since it seems to be a point of some contention. How to prove that $\frac{x^2}{yz+2}+\frac{y^2}{zx+2}+\frac{z^2}{xy+2}\geq \frac{x+y+z}{3}$ holds for any $(x,y,z)\in[1,2]^3$ Prove that for $x,y,z\in [1,2]$ the following inequality holds: $$\frac{x^2}{yz+2}+\frac{y^2}{zx+2}+\frac{z^2}{xy+2}\geq \frac{x+y+z}{3}.$$ I tried to apply the Cauchy-Schwarz inequality or the power mean inequality, but my attempts were unsuccessfull, so I am asking for help. How to get the type of T from a member of a generic class or method Let's say I have a generic member in a class or method, like so: public class Foo&lt;T&gt; {     public List&lt;T&gt; Bar { get; set; }          public void Baz()     {         // get type of T     }    }  When I instantiate the class, the T becomes MyTypeObject1, so the class has a generic list property: List&lt;MyTypeObject1&gt;. The same applies to a generic method in a non-generic class: public class Foo {     public void Bar&lt;T&gt;()     {         var baz = new List&lt;T&gt;();                  // get type of T     } }  I would like to know what type of objects the list of my class contains. So what type of T does the list property called Bar or the local variable baz contain? I cannot do Bar[0].GetType(), because the list might contain zero elements. How can I do it?