如何将列表内部字符串中的字符传递到列表列表中
How can I pass the characters in the string inside of the list into the list of lists
我正在尝试暴力破解扫雷游戏的所有可能解决方案作为我的作业,但我不知道如何将列表内部字符串中的字符传递给列表列表。
[['1', '0'], ['1', '0']]
[[' ', ' '], [' ', ' ']]
['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
第一个是我的目标解板,第二个是我的空板,第三个是我的二进制列表。我想将所有数字传递给空板,如果它不等于目标板,我必须传递下一个二进制数
尝试这样的事情。如果您愿意,可以更改变量的名称。我只是做了一个快速代码。如果适合您,请将其标记为已接受的答案。
x=['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
# pick one item at a time
for item in x:
finList = []
l1 = []
l2 = []
count = 1
# get individual digits from the string, like from '0001' you will get 0 then 0 then 0 then 1
for digit in item:
if count<=2:
l1.append(digit)
count += 1
else:
l2.append(digit)
finList.append(l1)
finList.append(l2)
print(finList)
我正在尝试暴力破解扫雷游戏的所有可能解决方案作为我的作业,但我不知道如何将列表内部字符串中的字符传递给列表列表。
[['1', '0'], ['1', '0']]
[[' ', ' '], [' ', ' ']]
['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
第一个是我的目标解板,第二个是我的空板,第三个是我的二进制列表。我想将所有数字传递给空板,如果它不等于目标板,我必须传递下一个二进制数
尝试这样的事情。如果您愿意,可以更改变量的名称。我只是做了一个快速代码。如果适合您,请将其标记为已接受的答案。
x=['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
# pick one item at a time
for item in x:
finList = []
l1 = []
l2 = []
count = 1
# get individual digits from the string, like from '0001' you will get 0 then 0 then 0 then 1
for digit in item:
if count<=2:
l1.append(digit)
count += 1
else:
l2.append(digit)
finList.append(l1)
finList.append(l2)
print(finList)