Code tip: use `dict.get()` to avoid KeyErrors
price = prices["BTC"]
Do this:
price = prices.get("BTC", 0) # default value if missing
Super useful when parsing messy JSON / market data feeds.
1
0 comments
Steven Maharaj
2
Code tip: use `dict.get()` to avoid KeyErrors
Coder Trader
skool.com/coder-trader
- Learn how to code
- Build Trading Systems
Powered by