擅长:python、mysql、java
<p>排序和筛选:</p>
<pre><code> # keep models together and sort by lowest price
srt = sorted(cars, key=lambda x: (x["model"], x["price"]))
# add cheapest of first model in the list
final = [srt[0]]
for d in srt[1:]:
if final[-1]["color"] != d["color"]:
final.append(d)
print final
[{'color': 'yellow', 'model': 'ferrari', 'price': 500}, {'color': 'red', 'model': 'ferrari', 'price': 1200}, {'color': 'blue', 'model': 'lamborgini', 'price': 2000}]
</code></pre>