I have a list which may be of any length. I have a method which calculates results for 50 elements at a time. I want to use the list in that manner such that for every iteration i get the next 50 elements.  What is did is, with the length of the list i calculated the no of times my loop should iterate,  count = math.ceil(len(newList)/float(50))   how should i iterate such that i can get the next 50 elements every iteration?  for c in range(0,count):     newList[:50]   how to get the next 50 and then next 50 ?
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:
Can't format my usb drive. I have already tried with mkdosfs and gparted I have a MicroSD card in a USB adapter (which plugs into a USB port on my machine, and acts like a USB flash drive). I was using Unetbootin to make this a bootable USB flash drive with Kubuntu. But I needed to cancel while it was working. So I killed the Unetbootin process from the console.  Since then, I can't format the MicroSD or delete the folder that Kubuntu made. I have also tried mkdosfs, with no success. I can't mount the drive anymore either? What can I do to make this drive usable again?  Trying to create a new partition table in GParted, as described in Eliah Kagan's answer, does not work. It fails with the error message "imposible crear tabla de particiones" ("unable to create a partition table"). XCOPY still asking (F = file, D = directory) confirmation Analogy: "as if" vs. "as though" This is something that confuses me from time to time. When making an analogy in literature, is it better to use the phrase "as if" or "as though", or is it completely a style thing?  E.g.      She looked frazzled, as if she had just gotten off of a roller coaster.   or     She looked frazzled, as though she had just gotten off of a roller coaster. How to backup an Android device? Can anyone recommend a good way to backup Android devices? Ideally I would like to do this wirelessly and, not only backup my data, but also my user settings. Is it possible to backup an image of an Android device - so that one doesn't even need to reinstall apps? It would be particularly useful to hear from users that have restored backups, as to how easy, and complete, their processes were. Thanks Sort a Map by values Can I levitate an object without using an electromagnet? I'm wondering how to approach duct work, piping, and wiring? In the past, I have used the spin tool to make corners, but I find it very cumbersome. How do you do duct work and piping? I have seen people use curves, but I find it's hard to get straight 90 degree angles or just uniform angling across the whole model. It's also hard connecting piping together if they started from different locations. Here's some reference: Delete all but top n from database table in SQL What's the best way to delete all rows from a table in sql but to keep n number of rows on the top? After reading an article about Ubuntu's netflix support I decided to try running netflix through chromium but I got this error code: M7063-1913 I assumed that it was a problem with html5 but in the playback preferences it doesn't give me the option to use it. What is the best way to clone/deep copy a .NET generic Dictionary? Am I correct to say the difference between a signed and unsigned integer is:  Unsigned can hold a larger positive value and no negative value. Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative. Signed integers can hold both positive and negative numbers.  Any other differences? How can I reliably get the operating system's name? Say I am logged into a remote system, how can I know what it's running? On most modern Linuxes (Linuces?), you have the lsb_release command:  $ lsb_release -ic     Distributor ID: LinuxMint Codename:       debian   Which as far as I can tell just gives the same info as /etc/lsb-release. What if that file is not present? I seem to recall that the lsb_release command is relatively new so what if I have to get the OS of an older system?  In any case, lsb stands for Linux Standard Base so I am assuming it won't work on non-Linux Unices. As far as I know, there is no way of getting this information from uname so how can I get this on systems that do not use lsb_release? Apache on MacOS Sierra: AH00557: httpd: apr_sockaddr_info_get() failed for Macbook-Pro.local AH00558: httpd: Could not reliably determine… I updated MacOS Sierra's Apache and PHP, and now whenever I $ sudo apachectl restart I get this:  AH00557: httpd: apr_sockaddr_info_get() failed for My-MacBook-Pro.local AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message   Things I've tried so far that didn't work:   Setting ServerName localhost in /etc/httpd.conf Setting ServerName localhost:80 in /etc/httpd.conf Setting ServerName 127.0.0.1 in /etc/httpd.conf Setting ServerName 127.0.0.1:80 in /etc/httpd.conf Ensuring 127.0.0.1       localhost is set in /etc/hosts Repeatedly restarting Apache If you have the ability to cast a spell without a spell slot, can you cast that spell using a spell slot? A 10th level Drow warlock (for instance) has the following Drow Magic racial trait (PHB p. 24), in addition to its warlock spellcasting abilities:  You know the dancing lights cantrip. When you reach 3rd level, you can cast the faerie fire spell once per day. When you reach 5th level, you can also cast the darkness spell once per day. Charisma is your spellcasting ability for these spells.  Can the Drow warlock cast faerie fire (which is not on the warlock spell list) using a warlock spell slot? Can it cast darkness (which is on the warlock spell list) using a warlock spell slot?  The  says this about the Magic Initiate feat:  If you’re a spellcaster, can you pick your own class when you gain the Magic Initiate feat? Yes, the feat doesn’t say you can’t. For example, if you’re a wizard and gain the Magic Initiate feat, you can choose wizard and thereby learn two more wizard cantrips and another 1st-level wizard spell. If you have spell slots, can you use them to cast the 1st-level spell you learn with the Magic Initiate feat? Yes, but only if the class you pick for the feat is one of your classes. For example, if you pick sorcerer and you are a sorcerer, the Spellcasting feature for that class tells you that you can use your spell slots to cast the sorcerer spells you know, so you can use your spell slots to cast the 1st-level sorcerer spell you learn from Magic Initiate. Similarly, if you are a wizard and pick that class for the feat, you learn a 1st-level wizard spell, which you could add to your spellbook and subsequently prepare.  But this specifically requires you to pick the feat for one of your classes to be able to cast the spell learnt using your class spell slots, and does not seem directly applicable. A Warlock can use warlock Pact Magic spell slots to cast spells learnt from levels of another spellcasting class, per the multiclass spellcasting rules (PHB p. 164):  If you have both the Spellcasting class feature and the Pact Magic class feature from the warlock class, you can use the spell slots you gain from the Pact Magic feature to cast spells you know or have prepared from classes with the Spellcasting class feature, and you can use the spell slots you gain from the Spellcasting class feature to cast warlock spells you know.  Similarly, if the warlock has learnt the invocation Mask of Many Faces (PHB p. 112)...  You can cast disguise self at will, without expending a spell slot.  ...Can the warlock cast disguise self using a spell slot, e.g. to decrease the chance it can be dispelled? Point reflection over a line I'm having trouble understanding the solution presented below (It's from a textbook). I tried to get something similar, but to no avail. Help me find the way he derived those a,b,x2 and y2 expressions.   Point p is a point which we want to reflect (It's a simple structure with two integers x and y representing coordinates on a 2d plane); (x0,y0) and (x1,y1) are coordinates of endpoints of a line.  Expected result is a new point with reflected coordinates.   Point mirror(Point p, int x0, int y0, int x1, int y1) {     double dx,dy,a,b;    long x2,y2;    Point p1; //reflected point to be returned      dx  = (double) (x1 - x0);    dy  = (double (y1 - y0);     a   = (dx * dx - dy * dy) / (dx * dx + dy*dy);    b   = 2 * dx * dy / (dx*dx + dy*dy);     x2  = Math.round(a * (p.x - x0) + b*(p.y - y0) + x0);     y2  = Math.round(b * (p.x - x0) - a*(p.y - y0) + y0);     p1 = Point((int)x2,(int)y2);      return p1;  } How can I create an instance of the Java console inside of a GUI panel? Terence Tao, Analysis I, Ex. 5.5.2: Entry point needed Motor to spin slowly, low torque I had to write the proof to show that an Ideal $P$ of a commutative ring $R$ is prime Ideal if $R/P$ is an integral domain.       let $a,b\in R$ s.t. $ab\in P$ ,        $$ab+P=P\implies(a+P)(b+P)=P\implies\overline a \overline b=0$$  and as $R/P$ is an integral domain either $a=0$ or $b=0$ $\implies a+P=P$ or  $b+P=P$.        $\therefore$ either $a\in P$ or $b\in P$.   Hence, $P$ is a prime Ideal.    Am I correct in writing this or am I making some error... How to open pdf file in Windows Phone 8?