小编Nik*_*ino的帖子

使用单行for循环python附加到空列表

我试图使用单行for循环将数字从生成器附加到空列表,但它返回None.我理解它可以使用2行的for循环完成,但我想知道我缺少什么.即

>>> [].append(i) for i in range(10)

[None, None, None, None, None, None, None, None, None, None]

我希望在一行中创建它:

>>> [].append(i) for i in range(10)

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

谢谢.

list append python-3.x

5
推荐指数
1
解决办法
1万
查看次数

使用Boost Graph [BGL]检查add_edge之前的顶点是否已经存在

有没有办法检查使用Boost创建的图形中的顶点是否已经存在,而不是遍历这些顶点?

如果已经存在,如何使用其顶点描述符添加新边?

例:

Graph g;
vertex v;

v = add_vertex(1, g);
vertex_name[v] = "root";

v = add_vertex(2, g);
vertex_name[v] = "vert_2";

v = add_vertex(3, g);
vertex_name[v] = "vert_3";

// This is not possible
edge e1;
if (vertex.find("root") == vertex.end()) {
   (boost::add_edge("root", "vert_2", g)).first
}
Run Code Online (Sandbox Code Playgroud)

c++ boost-graph

4
推荐指数
1
解决办法
878
查看次数

标签 统计

append ×1

boost-graph ×1

c++ ×1

list ×1

python-3.x ×1