小编shu*_*amj的帖子

Python将数组追加到数组

我目前正在开发DES实现,在代码的一部分中,我必须将数组追加到数组中,下面是我的代码:

C0=[1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1]

def Fiestel():
    C=[]
    C.append(C0)
    temp=[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]
    C.append(temp)
    print(C)
Fiestel()
Run Code Online (Sandbox Code Playgroud)

如何将数组附加到现有数组上,甚至尝试将C声明为2d数组。感谢您的帮助。

每个元素本身就是一个数组。

在此处输入图片说明

python arrays

5
推荐指数
2
解决办法
2万
查看次数

二维数组Python:列表索引超出范围

我是 Python 编程的新手,我正在尝试编写代码来检查 DFA(确定性有限自动机)是否具有空语言。

我正在使用二维数组来存储 DFA 的状态。在执行代码时,我不断让列表索引超出范围。我怎样才能解决这个问题?

下面是代码

top=-1
count=0
n=int(input("\nEnter the no of states"))
mat=[[]]
b=[]
print("\nEnter the transition table")
for i in range(0,n):
   for j in range(0,n):
    mat.append(input())
finalState=input("\nEnter the final state:")
startState=input("\nEnter the start state:")      

for i in range(0,n):
   for j in range(0,n):
      if mat[i][j]:
        b[++top]=j
for k in range(top):
      if b[k]==finalState:
      count+=1
if count>0:
print("\nLanguage is  not empty")
else:
print("\nLanguage is empty")
Run Code Online (Sandbox Code Playgroud)

python arrays

0
推荐指数
1
解决办法
4124
查看次数

标签 统计

arrays ×2

python ×2