ifとforを混ぜたリスト内包表記の書き方2020/6/5 / 1 min readView more blogs with the tag pythonTable of Contents#はじめに#方法はじめに これを一行のPythonコードで書きたい! columns = ['I am Sam', 'She is Erica', 'He is Eric']lst = []for c in columns: if 'Sam' in c: lst.append(c) print(lst)# ['I am Sam'] 方法 lst = [c for c in columns if 'Sam' in c]