数组名称中的串联
我想在 100 个数组中存储 100 个节点的详细信息。 例如,
节点 1
的邻居应存储在array1
,对于每个数组,名称应更改为 array1
、array2,
array3
, ..., array100
我需要使用 for< 连接数组和 ( 1 , 2 , 3 , ... , 100 ) /代码> 循环。
我该怎么做?
I want to store details of 100 nodes in 100 arrays.
For example,
neighbors of
node 1
should be stored inarray1
In this, for each array the names should be changed like array1
, array2
, array3
, ..., array100
I need the concatenation for array and ( 1 , 2 , 3 , ... , 100 ) using for
loop.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太确定你想要什么,但二维数组听起来像是正确的选择
Not exactly sure what you want, but a two dimensional array sounds like the way to go
通常建议使用二维数组(实际上只是复合元素名称),如下所示:
但是,如果您确实想创建这些名称,则可以通过多种方式来实现。一种是这样的:
但这很丑。当你来读取数组时就更丑了!更好的选择是:
请注意,如果您确实正在执行 2D 紧凑数字索引,那么您可能最好使用嵌套列表来构建矩阵:
It's usually recommended to use 2D arrays (really just composite element names) like this:
However, if you really want to be creating those names then you can do it in several ways. One is like this:
But that's ugly. It's even uglier when you come to read the arrays! A better choice is this:
Mind you, if you're really doing 2D compact numeric indices then you're perhaps better to use nested lists to build a matrix: