1 |
733
|
aaronmk
|
# Map spreadsheet manipulation
|
2 |
|
|
|
3 |
736
|
aaronmk
|
def merge_values(*vals):
|
4 |
|
|
new = []
|
5 |
|
|
for val in vals:
|
6 |
|
|
if val != '' and val not in new: new.append(val)
|
7 |
|
|
return '; '.join(new)
|
8 |
|
|
|
9 |
733
|
aaronmk
|
def merge_rows(*rows):
|
10 |
|
|
'''e.g. ['a','b'] + ['','y','z'] = ['a','b; y','z']'''
|
11 |
|
|
def get(row, i):
|
12 |
|
|
try: return row[i]
|
13 |
|
|
except IndexError: return ''
|
14 |
736
|
aaronmk
|
return [merge_values(*[get(row, i) for row in rows])
|
15 |
|
|
for i in xrange(max(map(len, rows)))]
|
16 |
735
|
aaronmk
|
|
17 |
|
|
def merge_mappings(in_, out):
|
18 |
|
|
'''e.g. ['in','join','in_comments'] + ['join','out','out_comments'] =
|
19 |
|
|
['in','out','in_comments; out_comments']'''
|
20 |
|
|
new = [in_[0], out[1]] # mapping
|
21 |
|
|
new[2:] = merge_rows(in_[2:], out[2:]) # comments
|
22 |
|
|
return new
|