How can arrange a set of names so that each solution has two names.for example ["bob", "sally", "jane"]
开发者_运维问答the outcome should be like; bob & sally, sally & jane etc, using python
Thanks in advance.
>>> import itertools
>>> li = ["bob", "sally", "jane"]
>>> for i in itertools.combinations(li, 2):
print i
And you get:
('bob', 'sally')
('bob', 'jane')
('sally', 'jane')
Check out the docs for itertools, especially on combinations and permutations. There are good code examples there showing how it really works.
精彩评论