Daily data work is lists and pairs: a list of products, a list of prices, name–price pairs. Python has two tools: list and dict.
List = an ordered list:
prices = [20000, 12000, 8000] prices[0] # 20000 — counting starts at 0 len(prices) # 3 prices.append(15000) # add
Dict = name→value pairs:
product = {"name": "ម្ហូបក្រៀម", "price_khr": 20000, "stock": 45}
product["price_khr"] # 20000
product["stock"] # 45
A common shape: a list of dicts — like a table:
rows = [
{"province": "សៀមរាប", "pop": 1000},
{"province": "បាត់ដំបង", "pop": 990},
]
rows[1]["province"] # បាត់ដំបង
This is the same structure pandas uses later.
Takeaways:
- List = ordered, starts at 0; dict = name→value pairs
- A list of dicts = a natural table
len(),append(),[]— the basic operations