使用操作员复制多维数组的元素

发布于 2025-02-07 06:53:49 字数 316 浏览 4 评论 0原文

我有这样的代码:

array = [['x', 3], ['y', 3]*2]
print(array)

输出:

>> [['x', 3], ['y', 3, 'y', 3]]

,但是,我想获得的结果是:[[['x',3],['' y',3],['y',3]]

我的问题是,如何使用 operators 复制多维数组的某个元素?

I have a code that goes like this:

array = [['x', 3], ['y', 3]*2]
print(array)

Output:

>> [['x', 3], ['y', 3, 'y', 3]]

However, the result that I want to get is: [['x', 3], ['y', 3], ['y', 3]]

My question is, how do you duplicate a certain element of a multi-dimensional array using operators?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2025-02-14 06:53:49

我不知道操作员的方法,但是
您可以使用copy()检查 docs

复制所需的元素,然后将其添加到数组中,

array = [['x', 3], ['y', 3]]
copy = array[1].copy()
array.append(copy)

您可以创建新的类类型并自定义运算符功能

I don't know a way for Operators But,
You can Use copy() Check the Docs

Copy the element you want then add it to the array

array = [['x', 3], ['y', 3]]
copy = array[1].copy()
array.append(copy)

You can create a new class type and customize the Operators functionality for it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文