[perl-python] generate all possible pairings

Xah Lee xah at xahlee.org
Sat Feb 26 20:26:31 EST 2005


20050226 exercise: generate all possible pairings

given a list that is a set partitioned into subsets, generate a list
of all possible pairings of elements in any two subset.

Example:

 genpair( [[9,1],[5],[2,8,7]] );

returns:

 [[5,8],[9,5],[1,5],[9,2],[9,7],[1,8],[1,7],[5,2],[1,2],[9,8],[5,7]]

(we do not assume the given set has order, so the result is not
ordered.)

Perl code and Python code will be posted in 2 days.

This is brought to you by the perl-python community. To subscribe, see
http://xahlee.org/perl-python/python.html

 Xah
 xah at xahlee.org
 http://xahlee.org/PageTwo_dir/more.html




More information about the Python-list mailing list