- 论坛徽章:
- 60
|
- #!/usr/bin/python
- #coding:utf8
- import fileinput
- files = ['a.txt', 'b.txt']
- handle_result = {}
- order_keys = []
- from_before = []
- from_after = []
- for line in fileinput.input(files):
- line_eles = line.strip().strip('|').split('|')
- k = line_eles[0]
- handle_result.setdefault(k, []).extend(line_eles[1:])
- if k not in order_keys:
- order_keys.append(k)
- if fileinput.filename() == files[0]:
- from_before.append(k)
- else:
- from_after.append(k)
- max_column = 0
- for k in order_keys:
- if max_column < len(handle_result[k]):
- max_column = len(handle_result[k])
- for k in order_keys:
- if k in from_before:
- while len(handle_result[k]) < max_column:
- handle_result[k].append('0.0')
- elif k in from_after:
- while len(handle_result[k]) < max_column:
- handle_result[k].insert(0,'0.0')
- for k in order_keys:
- print "%s|%s|" % (k,'|'.join(handle_result[k]))
复制代码 |
评分
-
查看全部评分
|