Hướng dẫn generate subsets python
I hadn't come across the The
The other examples here give the powerset of
The correct order for subsets should be the order which 'exhausts' the minimal distance first, like so:
Using numbers here makes this ordering look 'wrong', but consider for example the letters
This effect is more pronounced with more items, and for my purposes it makes the difference between being able to describe the ranges of the indexes of the powerset meaningfully. (There is a lot written on Gray codes etc. for the output order of algorithms in combinatorics, I don't see it as a side issue). I actually just wrote a fairly involved program which used this fast integer partition code to output the values in the proper order, but then I discovered
⇣
I wrote some more involved code which will print the powerset nicely (see the repo for pretty printing functions I've not included here:
This is all pretty simple, but still might be useful if you want some code that'll let you get straight to accessing the different levels of the powerset:
As an example, I wrote a CLI demo program which takes a string as a command line argument:
⇣ |