Python’s list comprehensions are great, but I’ve found a new (to me) use of them: iterating over a list and returning the first match when there might be multiple possible matches. (To be more accurate, my solution uses a generator expression rather than a list comprehension) In other words, I’m emulating a break statement in [...]
Category Archives: Programming
Accumulating dictionaries in Python
I often have a need to count tokens in a corpus. In Python, there are many ways to do this, but currently I most often use defaultdicts: 123d = defaultdict(int) for x in sequence: d[x] += 1 I would like to get rid of the for-loop and construct such a dictionary at once. I [...]
glot
What started as an attempt to make a desktop application for CEDICT turned into an ambitious attempt to create an omniformat dictionary database and interface. glot aims to be both a backend for managing and querying dictionaries of any (electronic) format–even those over network protocols like DICT–and also an intelligent interface for querying a massive [...]