Dùng list khi cần ordered collection có thể thay đổi.
- Dùng
tuplecho dữ liệu bất biến, làm dict key, trả về nhiều giá trị từ function. - Dùng
setđể loại bỏ duplicate và kiểm tra membership O(1). - Dùng
dictcho key-value lookup O(1). - Lưu ý:
setvàdictkhông ordered trước Python 3.7;dicttừ Python 3.7+ giữ insertion order.
Use list for ordered mutable collections.
Use tuple for immutable data, dict keys, or returning multiple values.
Use set to remove duplicates and O
- membership checks. Use
dictfor O - key-value lookups
Pitfall: set and dict were unordered before Python 3.7; dict maintains insertion order from 3.7+.