擅长:python、mysql、java
<p>这是您在评论Raymond的答案时所要求的,它只返回每个<code>x, y</code>对的最低<code>z</code>行:</p>
<pre><code>from operator import itemgetter
from itertools import groupby
from csv import reader
def min_z(iterable):
# the data converted from strings to numbers
floats = [[float(n) for n in row] for row in iterable]
# the data sorted by x, y, z
floats.sort(key=lambda (x, y, z, e): (x, y, z))
# group the data by x, y
grouped_floats = groupby(floats, key=itemgetter(slice(0, 2)))
# return the first item from each group
# because the data is sorted
# the first item is the smallest z for the x, y group
return [next(rowgroup) for xy, rowgroup in grouped_floats]
data = """-2.800000,-1.000000,5.470000,-0.26488315
-3.000000,1.000000,4.070000,-0.81185718
-2.800000,-1.000000,3.270000,1.29303723
-2.800000,-0.400000,4.870000,-0.51165026""".splitlines()
print min_z(reader(data))
</code></pre>
<p>印刷品:</p>
^{pr2}$