Let us have a list of strings: fruit = ["apple", "orange", "banana"]. I would like to have an output that prints out all the possible pairs, i.e.
apple - apple, apple - orange, apple - banana,
orange - orange, orange - banana,
banana - banana
My idea was to enumerate fruit and do the following:
for icnt, i in fruit:
jcnt = icnt
j = i
print ("icnt: %d, i: %s", icnt, i)
for jcnt, j in fruit:
print ("i: %s, j: %s", i, j)
Expectantly the string does not start from the icnt-th position but from the start. How to make the second loop to start from the i-th string?
itertools.combinationsitertools.combinationsbut to answer your question, you have to slice thefruitlist in the second loop like so:for jcnt, j in enumerate(fruit[icnt:]):Also if you are going to useenumerate, do so.