Python翻转字典,以及解决IndentationError: expected an indented block报错!

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!动手试试吧,有问题留言哈。看到就回复!