Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Re: Wrapping around a list Date: 27 Nov 2013 17:42:30 GMT Lines: 44 Message-ID: References: <35a56651-33b3-454e-a936-439196989d3b@googlegroups.com> X-Trace: individual.net nXd/N5cvs/YwwOln/aldeADUj973YvGA1lgsTI54bjZgXzWO2C Cancel-Lock: sha1:FqwFJpFrltuuOZDnYLZMXrZWWAQ= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:60624 On Wed, 27 Nov 2013 08:33:43 -0500, Neil Cerutti wrote: > On Wed, Nov 27, 2013 at 5:46 AM, wrote: >> I am working on a problem (Bioinformatics domain) where all >> possible combinations of input string needs to be printed as >> sublist >> >> For example: >> Input string : "LEQN" >> Output= "[L","E","Q","N"] >> ["LE","EQ","QN","NL"]["LEQ","EQN","QNE","NLE"]["LEQN"] > > How about itertools.combinations? > > import itertools > > s = "LEQN" > for i in range(len(s)): > for comb in itertools.combinations(s, i+1): > print(comb) > Output: > ('L',) > ('E',) > ('Q',) > ('N',) > ('L', 'E') > ('L', 'Q') > ('L', 'N') > ('E', 'Q') > ('E', 'N') > ('Q', 'N') > ('L', 'E', 'Q') > ('L', 'E', 'N') > ('L', 'Q', 'N') > ('E', 'Q', 'N') > ('L', 'E', 'Q', 'N') > > For some reason I've got more 2-character combinations than you, > though. The original poster's combinations comprise letters that are *contiguous*, in a circular sense. Yours include non-contiguous sets, like LQ. -- To email me, substitute nowhere->spamcop, invalid->net.