Groups of up to N items? I'm running Python 3.7.3.  I have an iterable which I want to group into iterables of up to N items.  This is almost the grouper() recipe from itertools, except that I don't want the last group padded.  The best I've been able to come up with is: from itertools import zip_longest  # From https://docs.python.org/3.7/library/itertools.html#itertools-recipes def grouper(iterable, n):     args = [iter(iterable)] * n     for group in zip_longest(*args):         yield (item for item in group if item)  names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] for group in grouper(names, 3):     print(list(group))  which does indeed do what I want: python group.py  ['a', 'b', 'c'] ['d', 'e', 'f'] ['g', 'h']  Is there something better/cleaner? Yeah, I know, this fails if any item is not truthy, but assume that's not a problem.
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:
Shell Type:  &gt;echo $SHELL /bin/ksh   Cronjob :   15 * * * * /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh &gt; /wls_domains/resMGT/logs/bea/data/script.log  The script is as below:  ##log files and lookup file "wlr3queue.txt" are in the same path of the script ##/wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh  Script :  #!/bin/ksh  dt=`date +%Y-%m-%d` xy=`date|awk '{print $4}'|awk -F":" '{print $1}'` yz=`expr $xy - 1` if [ $yz -le 9 ] then yz=0$yz fi  if [ $xy -gt 0 ] then  for i in `cat wlr3queue.txt` do  sum=0  count=`gzgrep -i "$dt" admin_resMGT_access.log* | grep "$yz:[0-5][0-9]" | grep "$i" | wc -l`  if [ $count -gt 0 ] then name=`echo $i | cut -d'/' -f3`  gzgrep -i "$dt" admin_resMGT_access.log* | grep "$yz:[0-5][0-9]" | grep "$i" | awk '{print $8}' &gt; consumed_time.txt  for j in `cat consumed_time.txt` do j_ms=`echo "$j * 1000" | bc` echo $j_ms &gt;&gt; consumed_ms_time.txt done  for k in `cat consumed_ms_time.txt` do sum=`echo "$sum + $k" | bc` done  avg=`echo "scale=2; ($sum/$count) "| bc`  min=`cat consumed_ms_time.txt | sort -n | head -1`  max=`cat consumed_ms_time.txt | sort -n | tail -1`  else  avg=0  min=0  max=0  fi ( echo $yz","$count","$avg","$min","$max )&gt;&gt;/wls_domains/resMGT/logs/bea/data/$name$dt.csv   rm -f consumed_ms_time.txt  done  else  echo "script won't execute at this hour" &gt; temp.txt  fi   I have executed the following commands and the script ran successfully.  ./wlr3queuetransaction.sh sh -x wlr3queuetransaction.sh /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh  /bin/ksh/ wlr3queuetransaction.sh.   How to debug? What to do? Most efficient way to convert an HTMLCollection to an Array Is there a more efficient way to convert an HTMLCollection to an Array, other than iterating through the contents of said collection and manually pushing each item into an array? How can I calculate what the effect of an extension tube will be? Geometric mean never exceeds arithmetic mean This was a mathematical induction question proposed in a textbook, and I've exhausted multiple approaches (proving RHS - LHS > 0, splitting the fraction, fractional exponents, etc.)     The geometric mean of $n$ positive numbers $a_1, a_2,\ldots,a_n$ is $\sqrt[n]{a_1a_2 \ldots a_n}$ and their arithmetic mean is $\frac{a_1+a_2+\ldots+a_n}{n}$. If $a_1, a_2,\ldots,a_n$ are $n$ positive real numbers, prove by induction that their geometric mean is always smaller than or equal to their arithmetic mean, i.e. $\sqrt[n]{a_1a_2\ldots a_n} \leq \frac{a_1+a_2+\ldots+a_n}{n}$ How many levels are there for Steam Trading Card badges? With the new Steam Trading Cards, I decided to craft the badge for CS:GO. I got this:    I then noticed that this is only a level 1 badge, and there was a level 2 badge to get. So I crafted it too:    Now it says there's a level 3 badge to get next. How many levels are there in total? Run script as root at login (no sudoer user, shell session) Much like /etc/profile and ~/.profile but ran by root instead of the user is doing login. /etc/rc.local runs after boot but I need running the script before login. The user is not a sudoer one.   Thanks! Grep: unexpected results when searching for words in heading from man page I'm running into weird behavior when trying to grep a man page on macOS. For example, the Bash man page clearly has an occurrence of the string NAME:  $ man bash | head -5 | tail -1 NAME   And if I grep for name I do get results, but if I grep for NAME I don't:  $ man bash | grep 'NAME' $ man bash | grep NAME   I've tried other uppercase words that I know are in there, and searching for SHELL yields nothing whereas searching for BASH yields results.  What's going on here?  Update: Thanks for all the answers! I thought it worth adding the context in which I ran into this. I wanted to write a bash function to wrap man and in cases where I've tried to look up the man page for a shell builtin, jump to the relevant section of the Bash man page. There might be a better way, but here's what I've got currently:  man () {   case "$(type -t "$1")" in     builtin)       local pattern="^ *$1"        if bashdoc_match "$pattern \+[-[]"; then         command man bash | less --pattern="$pattern +[-[]"       elif bashdoc_match "$pattern\b"; then         command man bash | less --pattern="$pattern[[:&gt;:]]"       else         command man bash       fi       ;;     keyword)       command man bash | less --hilite-search --pattern='^SHELL GRAMMAR$'       ;;     *)       command man "$@"       ;;   esac }  bashdoc_match() {   command man bash | col -b | grep -l "$1" &gt; /dev/null } Problem with \mkbibdateapalongextra of biblatex-apa biblatex-apa gives me this:  ! Undefined control sequence. &lt;argument&gt; \mkbibdateapalongextra                                {labelyear}{labelmonth}{labelday}\iffieldu...   I'm using the default (english) language, and have done the:  \DeclareLanguageMapping{norsk}{norsk-apa} \DeclareLanguageMapping{english}{american-apa}   thing.   Here's a short example:  \documentclass[english]{memoir} \usepackage{babel} \usepackage{roffe} \usepackage[backend=biber,date=short,maxcitenames=2,style=apa]{biblatex}  \DeclareLanguageMapping{norsk}{norsk-apa} \DeclareLanguageMapping{english}{american-apa} \addbibresource{Papers2.bib} \addbibresource{R.bib}  \begin{document} \cite{R-base}  \printbibliography \end{document}   This one replicates the problem. Shiny locked Legendaries in ORAS Serebii says that (probably) the only  in ORAS are Kyogre, Groudon, Rayquaza and Deoxys. This means that Reshiram and Zekrom, that were shiny locked in BW/B2W2, now can be found shiny.    Can anyone prove this? I'd like to know if it's true before waste hours in softresetting. I am trying to set up an operator to use the BoolTool after I set a position and modifier on Selected object and a different one on the Active object. I basically need to move the selected object up in Z and add a solidify modifier at .3 thickness, and to the Active I need to add a solidify at .1 thickness and remain in original position.  I thought I understood how to get this to work, but all I get is both modifiers on the Active object. Any hint as to where to go from here?  class SolidfyDifference(bpy.types.Operator): """Solidify and Difference Mask""" bl_idname = "object.solidfy_difference" bl_label = "Add Solidy and Difference Bool" bl_options = { 'REGISTER','UNDO' }  def execute(self, context):     scene = context.scene      sel = bpy.context.selected_objects     act = bpy.context.active_object        for obj in sel:         if obj != act:             bpy.ops.object.modifier_add(type='SOLIDIFY')             bpy.context.object.modifiers["Solidify"].thickness = 0.1        return {'FINISHED'} I'm creating a color object using the following code.  curView.backgroundColor = [[UIColor alloc] initWithHue:229 saturation:40 brightness:75 alpha:1];   How can I retrieve RGB values from the created color object? My competitor is using Alexa to see what I am doing. I need to get stop Alexa from including my sites in their rankings. How can I do so?   Is it possible to deny access to any visitor with the Alexa toolbar and deny access to Alexa bot requests? Split a string by spaces -- preserving quoted substrings -- in Python I have a string which is like this:  this is "a test"   I'm trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I'm looking for is:  ['this','is','a test']   PS. I know you are going to ask "what happens if there are quotes within the quotes, well, in my application, that will never happen. How do I transfer a Gmail account to a different Google account? How many ways can we let people into a movie theater if they only have half-dollars and dollars? My interest in combinatorics was recently sparked when I read about the many things that the Catalan numbers count, as found by Richard Stanley. I picked up a copy of Brualdi's Combinatorics, and while browsing the section on counting sequences I found a nice little puzzle that has definitely puzzled me.     Let $m$ and $n$ be nonnegative integers with $n\geq m$. There are $m+n$ people in line to get into a theater for which admission if $50$ cents. Of the $m+n$ people, $n$ have a $50$-cent piece and $m$ have a $\$ 1$ dollar bill. The box offices opens with an empty cash register. Show that the number of ways the people can line up so that change is available when needed is   $$ \frac{n-m+1}{n+1}\binom{m+n}{m}. $$     I first noted that the first person to enter must be one of the $n$ with a half-dollar. Now the register has a half-dollar change. The second person can be either a person with a half-dollar or a dollar. In the first case, the register will now have two half-dollars, in the second case, the register will now have one dollar bill. So it seems to me that when one of the $n$ people with a half-dollar enters, the number of half-dollars in the register increases by $1$, and when one of the $m$ people with a bill enters, the number of half-dollars decreases by $1$ but the number of bills increases by $1$.   I tried to model this by looking at paths in $\mathbb{Z}^2$. The $x$-axis is like the number of half-dollars, and the $y$-axis is the number of bills. You start at $(0,0)$, and you can take steps forward $(1,0)$ or backwards diagonally $(-1,1)$ corresponding to who enters, but you must always stay in the first quadrant of the plane without crossing over the axes. The goal is to make $m+n$ moves, and I figured maybe the number of such paths is counted by $\frac{n-m+1}{n+1}\binom{m+n}{m}$, but I'm not sure how to show this. I don't know if this observation simplifies the problem at all, as I don't know how to finish up. I'd be happy to see how this problem is done, thank you. How do I use superposition to solve a circuit? Yes, this is a pedagogical question. While answering another recent question, I wanted to refer the OP to concise instructions for using superposition to solve circuits. I found that all the easily found resources online were somewhat deficient. Typically they were unclear about what kinds of circuits superposition applies to, or about the actual method to apply the superposition theorem to a circuit problem. So,   What kinds of circuits can be solved by superposition?  How are different kinds of sources treated when solving by superposition?  What are the steps to solve a circuit using the superposition theorem? I am trying to ask a question on SE, have some mock data in Excel I've copied, and am simply trying to paste in to my question.  I've done this before dozens of times, but suddenly am having this issue.  However, when I do so, I get prompted to upload an image. (This happens with Ctrl + V and also right click --> Paste):    Am I overlooking something?  Edit: Playing around, I can copy from Firefox/browsers and Word, and paste in to the box as usual. Excel seems to be the only one giving the issue so far.  Edit2:  are still having this issue. How to quickly and safely defrost chicken? What is the safest, quick way to defrost chicken? Microwave? Running water over it? Prove that the multiplicative inverse of $a$ modulo $m$ exists if and only if $a$ and $m$ are coprime.  Can someone help me with this? How do I convert a SMP server world into a Single-player compatable world? I had a Minecraft world on Minefold.  I archived my Minecraft world just before Minefold closed about a year ago.  I'm trying now to open the world in my local Minecraft installation on OS X, but it doesn't show up in the worlds list.  To import it, I simply unzipped the archive from Minefold into my ~/Library/Application Support/minecraft/saves folder.  I'm running Minecraft 1.8, and I don't have any mods installed.  There's no error; the world just doesn't show up in my list of worlds after I click [Singleplayer] (or [Multiplayer]).  Now, the big clue is that the directory structures are different between my locally-created worlds and the world created on Minefold, but I can't figure out how to adapt the files to make them match:  This is a screenshot of my saves folder. I've circled in blue "local" and "minefold", which contain data files for the local and Minefold worlds, respectively.    I bracketed similar filenames in both worlds, but I'm flummoxed in that the Minefold version has three (3) sets of data files, whereas the local world has only one (1) set of files (even though I have visited Nether in the local world).  How do I load my old Minefold world locally?