Total Complexity | 5 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python |
||
2 | # encoding: utf-8 |
||
3 | |||
4 | |||
5 | def get_tags_count(journal): |
||
6 | """Returns a set of tuples (count, tag) for all tags present in the journal.""" |
||
7 | # Astute reader: should the following line leave you as puzzled as me the first time |
||
8 | # I came across this construction, worry not and embrace the ensuing moment of enlightment. |
||
9 | tags = [tag for entry in journal.entries for tag in set(entry.tags)] |
||
10 | # To be read: [for entry in journal.entries: for tag in set(entry.tags): tag] |
||
11 | tag_counts = {(tags.count(tag), tag) for tag in tags} |
||
12 | return tag_counts |
||
13 | |||
14 | |||
15 | def oxford_list(lst): |
||
16 | """Return Human-readable list of things obeying the object comma)""" |
||
17 | lst = sorted(lst) |
||
18 | if not lst: |
||
19 | return "(nothing)" |
||
20 | elif len(lst) == 1: |
||
21 | return lst[0] |
||
22 | elif len(lst) == 2: |
||
23 | return lst[0] + " or " + lst[1] |
||
24 | else: |
||
25 | return ", ".join(lst[:-1]) + ", or " + lst[-1] |
||
26 |