小编gra*_*per的帖子

Python数据结构

我对编程知之甚少,所以这是一个不知道在哪里寻找答案的情况.我想创建一个如下所示的数据结构:

vertexTopology = {vertexIndex: {clusterIndexes: intersection point}}
Run Code Online (Sandbox Code Playgroud)

但实际上,集群索引是由集群索引组成的集合.所以我现在真正拥有的是:

vertexTopology = {5: [[(1, 2, 3), intx_1], 
                      [(2, 3, 4), intx_2]]
                  6: [[(1, 2, 3), intx_3]]
                  ...}
Run Code Online (Sandbox Code Playgroud)

如何创建与每个集群及其顶点索引关联的唯一索引?就像是:

vertexTopology = {5: {index associated with (1, 2, 3) AND vertex 5, intx_1}, 
                     {index associated with (2, 3, 4) AND vertex 5, intx_2},
                  6: {index associated with (1, 2, 3) AND vertex 6, intx_3}]
                  ...}
Run Code Online (Sandbox Code Playgroud)

我不确定我要做的是最好用词典来实现,所以任何建议都受到欢迎!

贝娄是一个四点交叉的图像,所以你可以想象一下我处理的东西.

四点交叉口

python data-structures

12
推荐指数
2
解决办法
379
查看次数

在Python中检查set中的项目成员资格

您好我已经编写了几个月了,并且知道了基础知识,但是我遇到了一个集合成员问题,我无法找到解决方案.

我有一个整数对列表的列表,我想删除其中包含"a"整数的列表.我认为使用套装是最简单的方法.贝娄是代码:

## This is the item to test against. 
a = set([3]) 
## This is the list to test.      
groups = [[3, 2], [3, 4], [1, 2], [5, 4], [4, 3]]     

## This is a list that will contain the lists present
## in groups which do not contain "a"
groups_no_a = []        

for group in groups:
    group = set(group)
    if a in group:
        groups_no_a.append(group)
    ## I thought the problem had something to do with
    ## clearing the variable …
Run Code Online (Sandbox Code Playgroud)

python set

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

Python 迭代器中的反向列表

我希望从嵌套列表列表中创建两个字典:

M = {index of list: list}

N = {index of list: reversed list}
Run Code Online (Sandbox Code Playgroud)

例子:

对于初学者,我有以下列表:

L =  [[20, 56], [23, 24], [23, 12], [22, 21], [26, 48], [26, 24]]
Run Code Online (Sandbox Code Playgroud)

所以最终结果是:

M = {0: [56, 20], 1: [24, 23], 2: [12, 23], 3: [21, 22], 4: [48, 26], 5: [24, 26]}
N = {0: [20, 56], 1: [23, 24], 2: [23, 12], 3: [22, 21], 4: [26, 48], 5: [26, 24]}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个:

M = {}
N = {}
for index, …
Run Code Online (Sandbox Code Playgroud)

python reverse list

2
推荐指数
1
解决办法
1784
查看次数

标签 统计

python ×3

data-structures ×1

list ×1

reverse ×1

set ×1