Skip to content

Commit

Permalink
Simplify deduplication and sorting of collected designators
Browse files Browse the repository at this point in the history
  • Loading branch information
kvid committed Nov 16, 2020
1 parent 5409600 commit 0ebf547
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ def generate_bom(harness):
for group_entry in group_entries:
d = group_entry.get('designators')
designators.extend(d if isinstance(d, List) else [d] if d else [])
designators = list(dict.fromkeys(designators)) # remove duplicates
designators.sort()
total_qty = sum(entry['qty'] for entry in group_entries)
bom.append({**group_entries[0], 'qty': round(total_qty, 3), 'designators': designators})
bom.append({**group_entries[0], 'qty': round(total_qty, 3), 'designators': sorted(set(designators))})

bom = sorted(bom, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)

Expand Down

0 comments on commit 0ebf547

Please sign in to comment.