python 有两个文件,一个存储学号,姓名,另一个存储学号,成绩。通过学号,整合出姓名,成绩
python">#coding=utf-8 dictname ={} dictgrade = {} for line in open('C:\Users\xxx\Desktop\\name.txt'): param = line.split() params = {param[0]:param[1]} dictname.update(params) print dictname for item in open("C:\Users\xxxx\Desktop\grade.txt"): items = item.split() dictgrade[items[0]] = int(items[1]) print dictgrade dictstu={} for (key, name) in dictname.items(): value = dictgrade.get(key, '-') pitem = {name:value} dictstu.update(pitem) print dictstu