Last active
July 14, 2017 18:38
-
-
Save renzon/c581d498ab4ccea192f36429d4836cde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter, OrderedDict | |
def all_perms_r(curr, freqs): | |
if all(value==0 for value in freqs.values()): | |
yield curr | |
for ch, freq in freqs.items(): | |
if freq == 0: | |
continue | |
freqs[ch] -= 1 | |
yield from all_perms_r(curr + ch, freqs) | |
freqs[ch] += 1 | |
def all_perms_rep(a): | |
freqs = OrderedDict(sorted(Counter(a))) | |
yield from all_perms_r("", freqs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment