Divide set into subsets with equal number of elements
I would tackle this as follows:

Divide into 3 equal subsets.
Figure out the mean and variance of each subset.  From them construct an "unevenness" measure.
Compare each pair of elements, if swapping would reduce the "unevenness", swap them.  Continue until there are either no more pairs to compare, or the total unevenness is below some arbitrary "good enough" threshold.
For the purpose of conducting a psychological experiment I have to divide a set of pictures (240) described by 4 features (real numbers) into 3 subsets with equal number of elements in each subset (240/3 = 80) in such a way that all subsets are approximately balanced with respect to these features (in terms of mean and standard deviation).
Can anybody suggest an algorithm to automate that? Are there any packages/modules in Python or R that I could use to do that? Where should I start?