all permutations of a binary sequence x bits long

前端 未结 5 1170
陌清茗
陌清茗 2020-11-30 03:57

I would like to find a clean and clever way (in python) to find all permutations of strings of 1s and 0s x chars long. Ideally this would be fast and not require doing too m

5条回答
  •  旧时难觅i
    2020-11-30 04:51

    You can use itertools.product() for doing this.

    import itertools
    def binseq(k):
        return [''.join(x) for x in itertools.product('01', repeat=k)]
    

提交回复
热议问题