小编Jew*_*ile的帖子

如何获取其值包含另一个列表中至少一个项目的字典键?

我写了一个简单的脚本,其范围是:

list=[1,19,46,28 etc...]
dictionary={Joey:(10,2,6,19), Emily: (0,3), etc}
Run Code Online (Sandbox Code Playgroud)

现在我需要找到字典中所有值中至少有一个列表条目的键

示例:19是Joeys值,因此Joey是赢家.

我是怎么做到的(根本没有程序员)

# NodesOfSet = the list

# elementsAndTheirNodes = the dictionary

# loop as many times as the number of key:value entries in the dictionary element:nodes
# simply: loop over all the elements
for i in range (0, len (elementsAndTheirNodes.keys())):

    # there is an indent here (otherwise it wouldnt work anyway)
    # loop over the tuple that serves as the value for each key for a given i-th key:value
    # simply: …
Run Code Online (Sandbox Code Playgroud)

python dictionary list key-value

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

Python,从列表中弹出所有内容但最大值

我有一个列表,其中包含多达数千个条目及其值:

lst = [
    [entry1, [value1, value2, value3]],
    [entry2, [value4, value5, value6, value7]],
    ...
]
Run Code Online (Sandbox Code Playgroud)

需要从每个条目的值中弹出除最大值之外的所有内容.

你知道这样做的顺利方式吗?谢谢!

python list max

0
推荐指数
1
解决办法
85
查看次数

标签 统计

list ×2

python ×2

dictionary ×1

key-value ×1

max ×1