counting using variable length string as base

Gabriel Genellina gagsl-py2 at
Mon Mar 31 20:18:50 CEST 2008

En Mon, 31 Mar 2008 09:30:00 -0300, Graeme Glass <graemeglass at>  

> On Mar 27, 11:01 am, Peter Otten <__pete... at> wrote:
>> a b c aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc  
>> baa bab
>> bac bba bbb bbc bca bcb bcc
> Here is a cool solution we came up with during a little interactive
> session at our local meet up.
> (
> s = 'abcdef'
> ["".join([s[j] for j in range(len(s)) if x & (1 << j)]) for x in
> range(1,2**len(s)) ]

But it's doesn't generate the right sequence, and a lot of elements are  
missing. For 'abc':
['a', 'b', 'ab', 'c', 'ac', 'bc', 'abc']
It lacks ba, bb, ca, cb, cc, all b??, all c?? - see the sequence quoted  

Gabriel Genellina

More information about the Python-list mailing list