Code Lab BetaBUILD. RUN. DISCOVER.
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON STRUCTURES / CHAPTER 06 / Learn / LESSON 11
Counting with a dict beats nested loops:
counts = {} for word in ["a", "b", "a"]: counts[word] = counts.get(word, 0) + 1
get(word, 0) supplies 0 if missing. One pass O(n) instead of scanning all keys for every item.
Learn: one pass with dict.
AGGREGATE IDLE
›