Code N Curry MLCode & Curry ML
REFERENCE STATION

The Spice Rack 🧂

Every chef keeps their spices within arm's reach. Quick-reference cards for the syntax and formulas you grab mid-recipe.

pin these above your station! ↓

🐍 Python Essentials

the knife skills — reach for these daily
Variables & Types01
python
1
2
3
4
5
x = 42          # int
price = 99.5    # float
name = 'Chef'   # str
fresh = True    # bool
nothing = None  # null
f-Strings02
python
1
2
3
4
5
dish, qty = 'biryani', 3
f'{qty}x {dish}'
f'{price:.2f}'    # 2 decimals
f'{qty=}'         # qty=3
f'{name:>10}'     # right-align
Lists & Slicing03
python
1
2
3
4
5
6
menu = ['dal', 'naan', 'rice']
menu[0]      # 'dal'
menu[-1]     # 'rice'
menu[1:]     # ['naan','rice']
menu[::-1]   # reversed
menu.append('chai')
Dicts04
python
1
2
3
4
5
spice = {'heat': 7, 'salt': 2}
spice['heat']         # 7
spice.get('umami', 0) # default 0
spice.items()  # (key, value) pairs
spice.keys() | spice.values()
Comprehensions05
python
1
2
3
4
5
doubled = [x*2 for x in nums]
hot = [s for s in spices
       if s.heat > 5]
lookup = {s.name: s.heat
          for s in spices}
Functions06
python
1
2
3
4
5
6
def season(dish, salt=1):
    return f'{dish} +{salt} salt'

season('dal')           # default
season('dal', salt=3)   # keyword
square = lambda x: x*x
Loop Patterns07
python
1
2
3
4
5
6
for i, item in enumerate(menu):
    ...
for a, b in zip(list1, list2):
    ...
for k, v in spice.items():
    ...
Chef's Tip08

Truthiness: empty things ([], "", {}, 0, None) are False. Write "if menu:" not "if len(menu) > 0:".

Built-ins You Forget09
CallReturnsExample
sorted(xs, key=...)new sorted listsorted(dishes, key=lambda d: d.price)
enumerate(xs, 1)(index, item) pairsnumbered menu from 1
zip(a, b)paired tuplesnames with prices
any(...) / all(...)boolany(s.heat > 8 for s in spices)
range(start, stop, step)lazy int sequencerange(10, 0, -2)
Golden Rules10
  • Readability beats cleverness — code is read 10x more than written.
  • Name like a 3-star kitchen: learning_rate, not lr.
  • Mutating a list while looping over it burns the dish. Build a new one.
  • EAFP: try/except is more Pythonic than checking first.

FIG C.1: Python Essentials10 CARDS · TAPE TO STATION WALL