String loops in Python
- by Steve Hunter
I have two pools of strings and I would like to do a loop over both. For example, if I want to put two labeled apples in one plate I'll write:
basket1 = ['apple#1', 'apple#2', 'apple#3', 'apple#4']
for fruit1 in basket1:
basket2 = ['apple#1', 'apple#2', 'apple#3', 'apple#4']
for fruit2 in basket2:
if fruit1 == fruit2:
print 'Oops!'
else:
print "New Plate = %s and %s" % (fruit1, fruit2)
However, I don't want order to matter -- for example I am considering apple#1-apple#2 equivalent to apple#2-apple#1. What's the easiest way to code this?
I'm thinking about making a counter in the second loop to track the second basket and not starting from the point-zero in the second loop every time.