mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Commented on a nested list comprehension, following 244ae416
This commit is contained in:
parent
244ae416bb
commit
8daa1ef427
1 changed files with 3 additions and 0 deletions
3
jrnl.py
3
jrnl.py
|
@ -457,7 +457,10 @@ if __name__ == "__main__":
|
||||||
print(journal)
|
print(journal)
|
||||||
|
|
||||||
elif args.tags: # get all tags
|
elif args.tags: # get all tags
|
||||||
|
# Astute reader: should the following line leave you as puzzled as me the first time
|
||||||
|
# I came across this construction, worry not and embrace the ensuing moment of enlightment.
|
||||||
tags = [tag for entry in journal.entries for tag in set(entry.tags)]
|
tags = [tag for entry in journal.entries for tag in set(entry.tags)]
|
||||||
|
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]
|
||||||
tag_counts = {(tags.count(tag), tag) for tag in tags}
|
tag_counts = {(tags.count(tag), tag) for tag in tags}
|
||||||
for n, tag in sorted(tag_counts, reverse=True):
|
for n, tag in sorted(tag_counts, reverse=True):
|
||||||
print "%-20s : %d" % (tag, n)
|
print "%-20s : %d" % (tag, n)
|
||||||
|
|
Loading…
Add table
Reference in a new issue