我在python中的以下代码中遇到语法错误任何人都可以帮我解决这个问题吗?我的代码在下面给出
**from operator import itemgetter
d = {"A":1,"b":2,"c":5,"d":4}
print("original dic \n" ,d)
sor = sorted(d.itemsec), key=itemgetter(0)
print("in ascending order : " ,sor)
sor = sorted(d.itemsec), key=itemgetter(0), reverse=true
print("in reverse = " ,sor)
d.update({"v":7})
print("updated directery" ,d)
d1 = {"x":9}
d.update(d1)
print("concetinated dir = \n" ,d)
d2 = {"r":12, "s":14, "u":333}
d2.update(d)
print("merged dirs are = \n" )
print(d2)**
答案 0 :(得分:-1)
您的代码中有多处错误......
sorted
语句要求右括号括起来
它的所有论点。.items
或您使用的关键字。这是工作代码:
from operator import itemgetter
d = {"A":1,"b":2,"c":5,"d":4}
print("original dic \n" ,d)
sor = sorted(d, key=itemgetter(0))
print("in ascending order : " ,sor)
sor = sorted(d, key=itemgetter(0), reverse=True)
print("in reverse = " ,sor)
d.update({"v":7})
print("updated directery" ,d)
d1 = {"x":9}
d.update(d1)
print("concetinated dir = \n" ,d)
d2 = {"r":12, "s":14, "u":333}
d2.update(d)
print("merged dirs are = \n" )
print(d2)
祝你好运