google python class
Python Lists な練習問題にて。python って lambda 使えるんだよね、と言いつつ以下。
# C. sort_last # Given a list of non-empty tuples, return a list sorted in increasing # order by the last element in each tuple. # e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields # [(2, 2), (1, 3), (3, 4, 5), (1, 7)] # Hint: use a custom key= function to extract the last element form each tuple. def sort_last(tuples): # +++your code here+++ tuples.sort(key=lambda x: x[-1]) return tuples
なんつーか、わははは的。
でも python は lambda なナニにブロックも書けない模様。amachang の中の人の解が以下とのこと。
このエントリのソレは別途試験してみます。今日はもう死ぬ。