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で文字列からリストを作成する必要があり、[f(char) for char in string]に等しいf(x)の値を無視(リストに挿入しない)できるようにしたいと考えていますNone。
[f(char) for char in string]
None
どうやってやるの ?
「サブクエリ」を作成できます。
[r for r in (f(char) for char in string) if r is not None]
すべてのFalse値(0、False、Noneなど)も無視できるようにすると、次のfilterように使用できます。
filter
filter(None, (f(char) for char in string) ) # or, using itertools.imap, filter(None, imap(f, string))