1 Answer
1

Probably the most efficient simple way is to create a set of the codes, which will filter out uniques, then get the number of elements in that set:

count = len(set(d["code"] for d in li))

As always, I advise to not worry about this kind of efficiency unless you've measured your performance and seen that it's a problem. I usually think only about code clarity when writing this kind of code, and then come back and tighten it only if I've profiled and found that I need to make performance improvements.