- 论坛徽章:
- 4
|
本帖最后由 mswsg 于 2016-05-01 17:08 编辑
试试python http://bbs.chinaunix.net/thread-4244175-1-1.html- with open('1.txt', 'r') as f:
- alist = []
- d = {}
- lines = f.readlines()
- for line in lines:
- line = line.strip().split()
- alist.append(line)
- for i in alist:
- try:
- d[i[3]] += i[:-1]
- except KeyError:
- d[i[3]] = i[:-1]
- for course, score in d.items():
- if len(score) > 3:
- print course, float(score[0]) + float(score[3]), float(score[1]) + float(score[4]), \
- float(score[2]) + float(score[5])
- else:
- print course, ' '.join(score)
复制代码 |
|