相关疑难解决方法(0)

在Java中调用foreach循环中的remove

在Java中,使用foreach循环遍历集合时,对集合调用remove是否合法?例如:

List<String> names = ....
for (String name : names) {
   // Do something
   names.remove(name).
}
Run Code Online (Sandbox Code Playgroud)

作为附录,删除尚未迭代的项目是否合法?例如,

//Assume that the names list as duplicate entries
List<String> names = ....
for (String name : names) {
    // Do something
    while (names.remove(name));
}
Run Code Online (Sandbox Code Playgroud)

java foreach iterator loops

575
推荐指数
7
解决办法
41万
查看次数

如何从边列表构造一个面列表,具有一致的顶点排序?

我有一些看起来像这样的数据:

vertex_numbers = [1, 2, 3, 4, 5, 6]

# all order here is unimportant - this could be a set of frozensets and it would
# not affect my desired output. However, that would be horribly verbose!
edges = [
    (1, 2),
    (1, 3),
    (1, 4),
    (1, 5),

    (2, 3),
    (3, 4),
    (4, 5),
    (5, 2),

    (2, 6),
    (3, 6),
    (4, 6),
    (5, 6)
]
Run Code Online (Sandbox Code Playgroud)

上面的例子描述了一个八面体 - 对顶点1到6进行编号,其中1和6彼此相对,每个条目描述每个边的末端的顶点数.

从这些数据中,我想生成一个面部列表.面部保证是三角形的.这是上面输入的一个这样的面部列表,由手工确定:

faces = [
    (1, 2, 3),
    (1, 3, …
Run Code Online (Sandbox Code Playgroud)

python geometry graph-theory

13
推荐指数
1
解决办法
1555
查看次数

标签 统计

foreach ×1

geometry ×1

graph-theory ×1

iterator ×1

java ×1

loops ×1

python ×1