Revision 2415
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/lists.py | ||
---|---|---|
1 | 1 |
# Lists |
2 | 2 |
|
3 | 3 |
def is_seq(value): return isinstance(value, list) or isinstance(value, tuple) |
4 |
|
|
5 |
def uniqify(list_): |
|
6 |
'''Removes duplicates from a list. Preserves order.''' |
|
7 |
existing = set() |
|
8 |
new_list = [] |
|
9 |
for value in list_: |
|
10 |
if value not in existing: |
|
11 |
existing.add(value) |
|
12 |
new_list.append(value) |
|
13 |
return new_list |
lib/sql.py | ||
---|---|---|
634 | 634 |
|
635 | 635 |
def mk_flatten_mapping(db, into, cols, preserve=[], as_items=False): |
636 | 636 |
'''Creates a mapping from original column names (which may have collisions) |
637 |
to names that will be distinct among the given tables.
|
|
637 |
to names that will be distinct among the columns' tables.
|
|
638 | 638 |
This is meant to be used for several tables that are being joined together. |
639 |
@param into The table for the new columns |
|
639 |
@param cols The columns to combine. Duplicates will be removed. |
|
640 |
@param into The table for the new columns. |
|
640 | 641 |
@param preserve [sql_gen.Col...] Columns not to rename. Note that these |
641 | 642 |
columns will be included in the mapping even if they are not in cols. |
642 | 643 |
The tables of the provided Col objects will be changed to into, so make |
... | ... | |
648 | 649 |
* All mappings use the into table so its name can easily be |
649 | 650 |
changed for all columns at once |
650 | 651 |
''' |
652 |
cols = lists.uniqify(cols) |
|
653 |
|
|
651 | 654 |
items = [] |
652 | 655 |
for col in preserve: |
653 | 656 |
orig_col = copy.copy(col) |
Also available in: Unified diff
lists.py: Added uniqify()