-4

This is a procedure, I wanna convert it in one line:

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
Craicerjack
  • 6,203
  • 2
  • 31
  • 39
Deus Ralph
  • 23
  • 6

2 Answers2

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.")
gregory
  • 10,969
  • 2
  • 30
  • 42
0

Better explain what debris and product is next time, but I think you want this:

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

I assume debris and product are both strings for now.

Elmex80s
  • 3,428
  • 1
  • 15
  • 23