Can anyone solve this?
Stuart Ford
Stuart.Ford at Boeckh.com
Tue Jun 27 18:54:17 EDT 2000
More information about the Python-list mailing list
Tue Jun 27 18:54:17 EDT 2000
- Previous message (by thread): Can anyone solve this?
- Next message (by thread): Can anyone solve this?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
<rdudfield at my-deja.com> wrote in message news:<8j737m$t5a$1 at nnrp1.deja.com>... > Hi, > > I've got a problem here which I just can't figure out. > > > a = [1,2,3] > b = ["c",32] > c = [1,2] > > inputlist = [a,b,c] > > Inputlist can have any number of lists in it. The lists in it can have > any number of elements in them. > > I need the code to give every possible combination of the lists in > inputlist. > > This is what the answer should be for the inputlist above. > > outputlist = [[1, 'c', 1], [1, 'c', 2], [1, 32, 1], [1, 32, 2], [2, 'c', > 1], [2, 'c', 2], [2, 32, 1], [2, 32, 2], [3, 'c', 1], [3, 'c', 2], [3, > 32, 1], [3, 32, 2]] > [] > > Try this routine on... it's a kludge, but it works.. def combiner(inlist): outlist = [] indent = 0 command = '' for arg in inlist: command = command + indent*' ' + 'for xx' + `indent` + ' in inlist[' + `indent` + ']:\n' indent = indent + 1 command = command + indent*' ' + 'outlist.append([' for x in range(0, indent): if x == indent-1: command = command + 'xx' + `x` else: command = command + 'xx' + `x` + ',' command = command + '])\n' exec command return outlist Stuart
- Previous message (by thread): Can anyone solve this?
- Next message (by thread): Can anyone solve this?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list