小编CAV*_*AVS的帖子

获取字典中的n个最大键、值

number = 2
dct = {'a': 5,'b': 3,'c': 4}

for key,value in dct.items():
Run Code Online (Sandbox Code Playgroud)

我想检查字典中最大的值。支票取决于号码,因此在这种情况下,{'a':5, 'c':4}应该返回,因为号码是2。但是,如果数字为 1,则只{'a':5}应返回。我无法导入或使用 lambda

python dictionary python-3.x

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

Docstring具有不一致的前导空格

在以下代码中:

def read_file(filename):
    """
    >>> read_file('text.txt')
    {'Donald Trump': [('Donald Trump', 'Join me live in Springfield, Ohio!\nLit!!\n', 1477604720, 'Twitter for iPhone', 5251, 1895)]}
    """
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说:

ValueError: line 4 of the docstring for __main__.read_file has inconsistent leading whitespace: 'Lit!!'
Run Code Online (Sandbox Code Playgroud)

是什么原因引起了这个?

python docstring python-3.x

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

标签 统计

python ×2

python-3.x ×2

dictionary ×1

docstring ×1