Unyeilding a permutation generator

Gerard Flanagan grflanagan at gmail.com
Tue Nov 4 05:11:46 EST 2008


On Nov 3, 11:45 pm, silly... at yahoo.com wrote:
>
> Thats interesting code but seems to give a different output,
> suggesting thet the underlying algorithm is different.
> Ignoring linebreaks and case, the original code gives:
> abcd bacd bcad bcda acbd cabd cbad cbda acdb cadb cdab cdba abdc badc
> bdac bdca adbc dabc dbac dbca adcb dacb dcab dcba
>
> The output from the above program, when converted to strings is:
> abcd abdc acbd acdb adbc adcb bacd badc bcad bcda bdac bdca cabd cadb
> cbad cbda cdab cdba dabc dacb dbac dbca dcab dcba
>

Note:

    items = [''.join(p) for p in  perm('abcd') ]
    assert items == sorted(items)
    items = list(all_perms('abcd'))
    assert items != sorted(items)





More information about the Python-list mailing list