Revision 736
Added by Aaron Marcuse-Kubitza about 13 years ago
lib/maps.py | ||
---|---|---|
1 | 1 |
# Map spreadsheet manipulation |
2 | 2 |
|
3 |
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 |
|
|
3 | 9 |
def merge_rows(*rows): |
4 | 10 |
'''e.g. ['a','b'] + ['','y','z'] = ['a','b; y','z']''' |
5 | 11 |
def get(row, i): |
6 | 12 |
try: return row[i] |
7 | 13 |
except IndexError: return '' |
8 |
return ['; '.join(filter(lambda v: v != '', [get(row, i) for row in rows]))
|
|
9 |
for i in xrange(max(map(len, rows)))] |
|
14 |
return [merge_values(*[get(row, i) for row in rows])
|
|
15 |
for i in xrange(max(map(len, rows)))]
|
|
10 | 16 |
|
11 | 17 |
def merge_mappings(in_, out): |
12 | 18 |
'''e.g. ['in','join','in_comments'] + ['join','out','out_comments'] = |
Also available in: Unified diff
maps.py: Eliminate duplicates when merging values in the same column