-1

I'm having a code like this. Somehow i have simplify it using a for loop.

if set(u) & set(s1):
    u = u-s1
    print('s1')    
if set(u) & set(s2):
    u = u-s2
    print('s2')    
if set(u) & set(s3):
    u = u-s3
    print('s3')    
if set(u) & set(s4):
    u = u-s4
    print('s4')    
if set(u) & set(s5):
    u = u-s5
    print('s5')    
if set(u) & set(s6):
    u = u-s6
    print('s6')

I want to use a for loop to make it work like this

for i in range(1,7)
if set(u) & set(s **1to6** ) 
    u = u - s **1to6** 
    print ( s **1to6** )

1 Answers1

0

does this do what you want?

s = [s1, s2, s3, s4, s5, s6]
for sx in s:
    if set(u) & sx:
        u = u - sx
        print sx
scytale
  • 12,346
  • 3
  • 32
  • 46
  • Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. It's also recommended that you don't post an answer if it's just a guess. A good answer will have a plausible reason for why it could solve the OP's issue. – SuperBiasedMan Aug 25 '15 at 17:04