Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Pythonのwithキーワードはラムダ関数でどのように表現されていますか? 次の点を考慮してください。
with
def cat (filename): with open(filename, 'r') as f: return f.read()
ラムダ実装で失敗した試み:
cat = lambda filename: with open(filename, 'r') as f: return f.read()
lambda_form ::= "lambda" [parameter_list]: expression
withステートメントであり、lambda式のみを返すことはできません。
lambda
誰かがトリックを探している場合に備えて:
lambda filename: [(f.read(), f.close()) for f in [open(filename)]][0][0]