Wrapping around a list
ppearson at nowhere.invalid
Wed Nov 27 18:42:30 CET 2013
On Wed, 27 Nov 2013 08:33:43 -0500, Neil Cerutti <mr.cerutti at gmail.com> wrote:
> On Wed, Nov 27, 2013 at 5:46 AM, <amjadcsu at gmail.com> wrote:
>> I am working on a problem (Bioinformatics domain) where all
>> possible combinations of input string needs to be printed as
>> For example:
>> Input string : "LEQN"
>> Output= "[L","E","Q","N"]
> How about itertools.combinations?
> import itertools
> s = "LEQN"
> for i in range(len(s)):
> for comb in itertools.combinations(s, i+1):
> ('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,
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.
More information about the Python-list