Array
(
[2] => 19
[5] => 18
[8] => 15
[12] => 14
[15] => 13
[18] => 11
[23] => 9
)
我需要做的是检查我的a = ["000000001111111110101010","111111110000111111000011"]
,
list(a)
随机更改for item in a:
for elements in range(len(a[item])):
if "0" in a or "1" in a:
中的一个元素(0更改为1或1更改为0)只有一个元素,我该怎么做
在我的问题中,如果所有元素都改变了:
a[item]
如果只改变一个元素应为:
a = ["111111110000000001010101","000000001111000000111100"]
随机选择0或1更改为1或0
答案 0 :(得分:0)
以下源代码适用于我:
a = ['000000001111111110101010',"111111110000111111000011"]
print(a)
ret = []
for item in a:
r = ''
for i in item:
b = int(i, base=2)
c = str(int(not b))
r = r + c
ret.append(r)
print(ret)
输出是:
['000000001111111110101010', '111111110000111111000011']
['111111110000000001010101', '000000001111000000111100']
答案 1 :(得分:0)
以下是两者,翻转所有数字并翻转一个随机数字:
a: ['000000001111111110101010', '111111110000111111000011']
flip all: ['111111110000000001010101', '000000001111000000111100']
flip one: ['000000001101111110101010', '111111110000111110000011']
输出:
UNION