2017-02-18 4 views
-5

を使用して1行の手順のコードの多くの行を変換し、私は1つのラインでそれを変換したい:これは手続きであるのpython

def fix_machine(debris, product): 
    i=0 
    while(i<len(product)): 
     if(debris.find(product[i]) == -1): 
      return "Give me something that's not useless next time." 
      break 
     i = i + 1 
    return product 
+0

問題を説明しますか? –

+0

このコードを1行で変換したいと思います... @KhairulBasarRofi –

+0

'debris'と' product'のサンプル値を提供してください。 'debris'は文字列です。なぜなら' find'があるからです。そして 'product'は文字列のリストですか? –

答えて

0
debris = 'widget_z' 
product = ['widget_a', 'widget_b', 'widget_c', 'widget_d'] 

if debris not in product: print("Give me something that's not useless next time.") 
0

より良いものをdebrisproductは次回ですが、私は思うの説明します私はdebrisproduct今の両方の文字列であると仮定し

def fix_machine(debris, product):  
    if set(product) <= set(debris): 
     return product 
    else: 
     return "Give me something that's not useless next time." 

:あなたはこれをしたいです。

関連する問題