python中的多行列表理解

Igo*_*bin 4 python list

我如何在Python中创建多行列表理解?就像是:

[
  x for x in a:
    if check(x):
      ....
      #something multiline here
      ....
    else: 
      ....
      #something multiline here
      ....
]
Run Code Online (Sandbox Code Playgroud)

当然我知道我可以这样:

def f(x):
  if check(x):
     ....
  else: 
     ....
 return x

map(a,f)
Run Code Online (Sandbox Code Playgroud)

但我希望它没有额外的功能.

可能吗?

pyf*_*unc 5

我的理解是你不能按照你的建议去做.

当您命名函数并使用列表推导或映射函数与您建议的相比时,它更具可读性