Python将数组追加到数组 [英] Python appending array to an array

查看:781
本文介绍了Python将数组追加到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently working on DES implementation.In one part of the code I have to append array to an array.Below is my code:

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()

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

How do I append an array to an existing array.I even tried declaring C as 2d array.Thankx in advance for helping.

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

Each element is an array itself.

推荐答案

您可以使用 +运算符将一个列表的元素追加到另一列表。

You can append the elements of one list to another with the "+" operator.

a = [1, 2, 3]
b = [10, 20]

a = a + b
print a
# [1, 2, 3, 10, 20]

如果要追加列表并将其保留为列表,请尝试:

If you want to append the lists and keep them as lists, then try:

result = []
result.append(a)
result.append(b)
print result
# [[1, 2, 3], [10, 20]]

这篇关于Python将数组追加到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆