1,Windows+R启动:运行
Python翻转字典,以及解决IndentationError: expected an indented block报错!2,输入:cmd 回车打开!
Python翻转字典,以及解决IndentationError: expected an indented block报错!
3,输入python(假设你已经安装过了python)
里面还会出现版本号!
Python翻转字典,以及解决IndentationError: expected an indented block报错!4,输入代码:
注意:如果空格缩进不对,会报错的!
比如:
Python翻转字典,以及解决IndentationError: expected an indented block报错!

下面是正确的代码!

d1 = {"zhang":123,'wang':456,'lk':123,'zhao':456}
d2 = {}

for name, room in d1.items():
    if room in d2:#4个空格
        d2[room].append(name)#8个空格
    else:#4个空格
        d2[room] = [name]#8个空格

print d2

执行结果:
Python翻转字典,以及解决IndentationError: expected an indented block报错!
5,OK!动手试试吧,有问题留言哈。看到就回复!

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-06-17
  • 2021-10-21
猜你喜欢
  • 2021-10-18
  • 2021-06-02
  • 2022-12-23
  • 2021-08-25
  • 2021-11-24
  • 2021-08-30
相关资源
相似解决方案