将零添加到列表中
我正在尝试找到一种方法使两个列表的长度相同。如何向一个列表添加零以使其与第一个列表具有相同的长度?
即list1=[ 1 2 3 4 5];列表2=[ 1 2 3]
I am trying to find a way to make two lists the same length. How can I add zeros to one list so as to make it have the same length with the first one?
i.e. list1=[ 1 2 3 4 5]; list2=[ 1 2 3]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有很多方法可以做到这一点。其中一种是
另一种方法是
这两种方法都假设
list2
比list1
短。There are many ways you can do that. One of them is
Another way is
Both of these ways assume that
list2
is shorter thanlist1
.这是针对您知道 list2 比 list1 短的情况的单行代码
Here's a one-liner for the case where you know list2 is shorter than list1
假设您不知道两个列表中哪一个更大。您可以执行以下操作:(
这适用于八度)
Assuming that you do not know which of the two lists is bigger. You can do the following:
(This works on octave)