Tag: operator
4 รายการ
Blog
pythonoperatorfunctional-programming
Python operator.call: ส่งฟังก์ชันเข้า pipeline แบบไม่ต้องห่อ lambda
ใช้ operator.call เรียก callable ใน functional pipeline พร้อมรู้ว่าความอ่านง่ายสำคัญกว่าความสั้น
pythonoperatorstdlib
Python operator.methodcaller: เรียกเมธอดเป็นคีย์เรียง/แมปโดยไม่เขียนแลมบ์ดา
ใช้ operator.methodcaller สร้าง callable ที่เรียกเมธอดชื่อเดิม พร้อมอาร์กิวเมนต์ คู่กับ sorted/map
pythonoperatorstdlib
operator.attrgetter: ดึงฟิลด์เรียง/แมปโดยไม่เขียน lambda ซ้ำ
ใช้ operator.attrgetter ดึง attribute เดี่ยวหรือหลายตัว รวม dotted path สำหรับ sorted และ map
pythonsortingoperator
Python itemgetter: เขียน sort key หลายช่องให้สั้นและเห็นลำดับชัด
ใช้ operator.itemgetter เรียง record ตามหลายฟิลด์ พร้อมจัดการค่ากลับทิศและข้อจำกัดของข้อมูลที่อาจขาด