2016-07-20 7 views
0

リスト内包中に複数のパラメータを除外するにはどうすればよいですか?ネストされた理解 - ifループ内の内側ループ

私は簡単な式があります:[E場合ではないx.thingにブロブ中のxについてx]は データを=

しかし代わりに、1つの文字列「E」の私は、複数の文字列 をテストしたいと思いますので、少し擬似コードの:私は除外の長さまたは値を知らない

exclude = ['tom', 'dick', 'harry', ....] 
data = [x for x in blob if <any of the values of exclude> not in x.thing] 

ので、私は

[x for x in blob if e1 not in x.thing else x for x in blob if e2 not in x.thing else ... ] 
+0

それはあまり意味がありません。あなたの質問を編集し、理解することなく達成しようとしているものを追加してください。 – DeepSpace

答えて

0

はちょうどこの行をコピー&ペースト、これを試して行うことはできません。例えば

[x for x in blob if all(e not in x.thing for e in exclude)] 

入力:

exclude = ['tom', 'dick', 'harry'] 
blob=['franceharry','germany','gerrytom'] 
[x for x in blob if all(e not in x for e in exclude)] 

出力:

['germany'] 
関連する問題