小编Muk*_*rma的帖子

无法在python中导入破折号

我无法运行任何破折号程序。我得到了错误。

Dash was not successfully imported. Make sure you don't have a file named
'dash.py' in your current directory.
Run Code Online (Sandbox Code Playgroud)

还要检查一下,我尝试在终端中从 python 导入破折号,令人惊讶的是我可以在终端中导入破折号,其中目录不包含带有破折号导入的 .py 文件,而如果任何文件中包含导入破折号,我不能在该目录的终端中导入破折号。附上的图片会帮助你。在两个不同的终端、两个不同的目录中导入破折号

python plotly plotly-dash

8
推荐指数
4
解决办法
9035
查看次数

创建一个字典,将列表中元素的长度作为键

我有一个列表,其中有多个作为元组存储在列表中的元素,我想创建一个字典,其中键的长度为1,2等,而各个长度的元素。清单的例子是

combination = [('A',), ('B',), ('C',), ('D',), ('A', 'B'), ('A','C'),
 ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D'), ('A', 'B', 'C'), 
('A', 'B', 'D'), ('A', 'C', 'D'), ('B', 'C', 'D'),('A', 'B', 'C', 'D')]
Run Code Online (Sandbox Code Playgroud)

我试过了 temp_dict = {len(i): i for i in combinations}

所需的输出是

{1: [('A',), ('B',), ('C',), ('D',)], 2: [('A', 'B'), ('A','C'),
 ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')], 3: [('A', 'B', 'C'), 
('A', 'B', 'D'), ('A', 'C', 'D'), ('B', 'C', 'D')], 4: [('A', 'B', 'C', 'D')]}```
Run Code Online (Sandbox Code Playgroud)

python dictionary list

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

标签 统计

python ×2

dictionary ×1

list ×1

plotly ×1

plotly-dash ×1