我有一本包含唯一 ID、姓名和生日的字典。这本字典就像一个生日数据库,我的挑战是我不知道如何在其中放入多个 ID。
db = {"id": 1, "fn": "JM", "ln" : "Cruz", "dob": "October 5, 1980"}
db1 = {"id": 2, "fn": "JD", "ln" : "Castillo", "dob": "August 18, 1979"}
db2 = {"id": 3, "fn": "Maria", "ln" : "Torres", "dob": "August 3, 1992"}
print("ID: " + str(db["id"]))
print("Full Name: " + db["fn"] + " " + db["ln"])
print("Birthday: " + db["dob"])
print("----------------------")
print("ID: " + str(db1["id"]))
print("Full Name: " + db1["fn"] + " " + db1["ln"])
print("Birthday: " + db1["dob"])
print("----------------------")
print("ID: " + str(db2["id"]))
print("Full Name: " + db2["fn"] + " " + db2["ln"])
print("Birthday: " + db2["dob"])
print("----------------------")
在上面的代码中,您会注意到我必须重复创建字典才能枚举多组 ID、姓名和生日。有没有办法将这些键转换为变量,并给出相同的输出?
开满天机
jeck猫
三国纷争
相关分类