How to construct a tuple of two from list How to construct a list of tuple from a list.  Let a list data_set be  data_set = ['a', 'b', 'c', 'd']   Output I needed is   tuple_set = [('a', 'b'), ('c', 'd')]   I am new to python, a little help 'd be greatly appreciated.  Thanks in advance
How do you split a list into evenly sized chunks? 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:
How to change programmatically exposed filters in views I have a page view with exposed filters. One of the filters is term vocabulary, and that's dropdown list, user can select only one category (term).   I want to set programmatically one term from dropdown list when I came from specific URL. I tried with views_query_alter where $category is tid.    $set_exposed_input  = array();  $set_exposed_input['field_category_tid'] = $category;   if ($set_exposed_input) {     $view-&gt;set_exposed_input($set_exposed_input);  } so I am creating a few posts about bearings and wheels, (story so far):      I have now got the wheels, bearings and freehub working.  Started riding to work this morning and I almost couldn't stop at a junction.  Thankfully wasn't going too fast.  I physically can not get the wheel to lock.  I have to use both brakes at full force to get the bike to roll to a stop.  If I only use one brake I would not stop at any junction in time.  Could the cause be any of the following:   Over greased bearings? Over greased axle? not tightened cone hubs enough? not tighted axle enough?   I do not have any grease on the disk brakes them selves.  Rather nervous getting on the bike now.  Don't seem to be doing too well with this bike home fixing thing.  over greased bearings?  EDIT  Forgot to mention that it is hydraulic disk brakes.  EDIT 2  So in the end I took it to the LBS as I didn't have much confidence in my self at this point.  They had to replace the front pads but where able to clean the rear and cleaned the rotors.  (I had tried to clean the rotors but obviously not vigorously enough).  He said it was a bit of a pain to do.  All is working again.  They double checked my wheels and said I had put them back together correctly which is reassuring.  Thanks for all the help Suggested reading for renormalization (not only in QFT) I've inherited a Maintenance Plans that does the following:   Cleanup old data Checks DB integrity Performs Database and Transaction Log Backups Reorganizes Our indexes Updates Statistics Delete old backups and Maintenance Plan files   Of the 23 minute Maintenance Plan, Updating the Statistics takes a staggering 13 minutes. During this 13 minute period, access to the database is blocked (or at least, replication from this DB to our others is paused).  My Question Is:  When should we be Updating the Statistics, and why?   This seems like the kind of thing we should do less frequently than every day. I'm trying to get us out of the "just because" mind-set of doing unnecessary Maintenance. What is the easiest way to resolve apt-get BADSIG GPG errors? I frequently cross this issue, and always have to google for an answer. Does anyone have a permanent fix for BADSIG errors from apt-get?     W: GPG error:    lucid   Release: The following signatures were   invalid: BADSIG 54422A4B98AB5139   Oracle Corporation (VirtualBox archive   signing key) Given a sphere of radius $r$ with two spherical caps on it defined by the radii ($a_1$ and $a_2$) of the bases of the spherical caps, given a separation of the two spherical caps by angle $\theta$, how do you calculate the surface area of that intersection?   To clarify, the area is that of the curved surface on the sphere defined by the intersection. At the extreme where both $a_1,a_2 = r$, we would be describing a spherical lune.   Alternatively define the spherical caps by the angles  $\Phi_1 = \arcsin(a_1/r)$ and $\Phi_2 = \arcsin(a_2/r)$. Started new job. Rollover previous employer 401k to new 401k, IRA or Roth IRA? How can I produce the text Word_one_two in LaTeX?  I tried:  Samp\_Dist\_Corr   But, it doesn't quite look right. Also, I want it in the typewriter font, so actually, I'm doing:  \texttt{Samp\_Dist\_Corr}   I find it looks a bit like the underscore is merging in to the bottom of the "D", but maybe it's just because of the typewriter D? Do I have 32-bit or 64-bit? Why would my TV image turn black when electrical appliances turn on? Distance metric for (infinite) lines in 3D I would like a metric $d(\;)$ between pairs of (infinite) lines in $\mathbb{R}^3$, with these properties:   If two lines $L_1$ and $L_2$ are parallel and separated by distance $x$, then $d(L_1,L_2) = x$. $d(L_1,L_2)$ increases with the degree of skewness between the lines, i.e., the angle $\theta$ between their projections onto a plane orthogonal to the shortest segment connecting them (dashed below), where $\theta=0$ for parallel lines and $\theta=\pi/2$ for orthogonal lines. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   Intuitively, I would like the metric to be related to the repulsive force between two electrically charged lines (but it need not be exactly the actual physical force).  Have such metrics been considered in the literature? If so, I'd appreciate descriptions and/or pointers&mdash;Thanks!  Update1. It turns out that the natural ad hoc definition (from the comments) fails to be a metric. For example, below, a sufficiently large value of $a$ ensures the triangle inequality will be violated: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; So this question may be more difficult than it initially appeared...  Update2.  The  have revealed that in fact there is no metric that satisfies my two conditions (and is continuous w.r.t. $\theta$)! What editors/IDEs are available for easing the process of writing TeX/LaTeX documents? Please state some useful features like code completion, spell checking, building final DVI or PDF files, etc.  This question is undergoing a systematic refurbishment, see  on Meta. If you’d like to see another editor feature covered here or to take care of an editor that’s not covered yet, share your ideas in that meta question.  List of editors Links to answers. Desktop link to Eclipse I was tring to install eclipse on ubuntu. What I did: I unzipped the tar archive of eclipse. I tried to start eclipse from the command line - like this - ./eclipse. It works. But then I tried to create a desktop icon with: gnome-desktop-item-edit ~/Desktop --create-new. In a new icon I showed the path to the eclipse executable which I could launch from the command line. But then eclipse does not start stating:  A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /home/artem/eclipse/jre/bin/java java in your current PATH   The same message appears if I try to launch eclipse by double-clicking its original launcher. So it starts from the terminal but not from the desktop (it does not start when double-clicked) And also I get a message in the terminal (at some stage it appeared):  (gnome-desktop-item-edit:8998): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.DSV8LW': No such file or directory   I am using Ubuntu 12.04 x32 and eclipse Juno.  PS. PATH variable points at jdk/bin and JAVA_HOME - to the jdk folder PSS. I actually set the environment variables through .bashrc file(JAVA_HOME and PATH) Should I use a canonical link which refers to the current URL with pagination? Product of an exponential function of IDD variables if $x_i$ are IID  continuous random variables, with $E[x_i]=μ$, is the following correct?   $E\left[\prod_{i=1}^n(1+⍺\space x_i)^i\right] = \prod_{i=1}^nE\left[(1+⍺\space x_i)^i\right] =  \prod_{i=1}^n(1+⍺\space E\left[x_i\right])^i = (1+⍺\space μ)^n$  thanks! Controlling the direction of curve extrusion Is there an easy way to control how the extruded width of a curve object is oriented, for example like this     or this     The curve in the images above has only two control points, and I got the effect by rotating one of the points. However, for a curve with lots of control points it would be somewhat difficult or at least tedious to achieve this. Is there a simpler way? Sampling with replacement or without replacement I'm writing a program in R that simulates bank losses on car loans.  Here is the questions I'm trying to solve:  You run a bank that has a history of identifying potential homeowners that can be trusted to make payments. In fact, historically, in a given year, only 2% of your customers default. You want to use stochastic models to get an idea of what interest rates you should charge to guarantee a profit this upcoming year.  A. Your bank gives out 1,000 loans this year. Create a sampling model and use the function sample() to simulate the number of foreclosure in a year with the information that 2% of customers default. Also suppose your bank loses $120,000 on each foreclosure. Run the simulation for one year and report your loss.  B. Note that the loss you will incur is a random variable. Use Monte Carlo simulation to estimate the distribution of this random variable. Use summaries and visualization to describe your potential losses to your board of trustees.   C. The 1,000 loans you gave out were for 180,000. The way your bank can give out loans and not lose money is by charging an interest rate. If you charge an interest rate of, say, 2% you would earn 3,600 for each loan that doesn't foreclose. At what percentage should you set the interest rate so that your expected profit totals 100,000. Hint: Create a sampling model with expected value 100 so that when multiplied by the 1,000 loans you get an expectation of 100,000. Corroborate your answer with a Monte Carlo simulation.  I'm confused about how to set up this simulation up from a high level point of view and have the following questions: 1. For part A, Should I create a pool of 1000 customers or should I create a larger pool of customers? 2. For part A, when sampling, do I sample with or without replacement? 3. For part B, I'm confused about how to set up the monte carlo simulation.  Am I varying the size of the customer pool? 4. For part C, I'm not sure how to set up a sampling model that involves the interest rate.  Any advice or guidance would be appreciated.  I'm also thinking that if I fully understood the high level concepts for parts A and B, part C might not be such a mystery. How to add http:// if it doesn't exist in the URL Forced to Quit PhD although the hard and proved work How do I configure Nautilus to open at my Documents folder instead of my home folder?  I've scoured this site and found answers instructing users to edit the /usr/share/applications/nautilus.desktop file, replacing %U with the path to the desired default directory. I've edited all the variants of nautilus.desktop in the said directory, but none of the edits has an effect. I've checked all the files after editing them to make sure that I saved the edit effectively, and all look good to me.   I've edited every file to read as follows:  Exec=nautilus --new-window /home/judy/Documents   I've also edited the org.gnome.Nautilus.desktop file, just to be sure, with no joy.   I'm running Ubuntu 15.10.  Note: if I enter nautilus /home/judy/Documents from the command line, Nautilus properly opens in the desired directory.  Is there a simple way that I can configure an icon in the launcher bar to run this command and have the Nautilus icon that looks like a metal file drawer?  Thanks. I'm pulling my hair out over this one.