在Python中生成二进制二进制数组 [英] Generating two-dimensional array of binaries in Python
本文介绍了在Python中生成二进制二进制数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我正在尝试的
list(itertools.combinations_with_replacement('01', 2))
但这正在生成[('0', '0'), ('0', '1'), ('1', '1')]
我仍然需要一个('1','0')
元组,是否可以使itertools也进行组合和排序?
I still need a ('1','0')
tuple, is there a way to make itertools also do combinations and order?
推荐答案
使用 itertools.product
代替:
>>> import itertools
>>> list(itertools.product('01', repeat=2))
[('0', '0'), ('0', '1'), ('1', '0'), ('1', '1')]
这篇关于在Python中生成二进制二进制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文