I have a list of items
alist = ['dog', 'cat', 'fish']
I want to return all unique unordered pairs, so in this case:
(dog,cat)(dog,fish)(fish,cat)
itertools.combinations
does not take into account the unordered condition, so it is not quite what I need.
Where is your problem with itertools?
import itertools
alist = ['dog', 'cat', 'fish']
for result in itertools.combinations(alist, 2):
print result
output:
('dog', 'cat')
('dog', 'fish')
('cat', 'fish')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With