functools.partial

PeerTube

Speed up costly LLM API calls with a tiny in‑memory cache using Python’s functools.lru_cache. Learn how a simple decorator can slash latency, reduce token costs, and keep your workflow pure Python—no extra services needed. Code snippets, performance graphs, and tips for swapping in diskcache when memory runs low. #Python #LLM #functools #LRUCache

🔗 https://aidailypost.com/news/python-functools-inmemory-caching-speeds-expensive-llm-api-calls

Mia Bajić: The Standard Library Tour @ PyCon Ireland 2023

https://youtu.be/ZId-JEMSCQ8

The Standard Library Tour is designed to provide attendees with an understanding of Python's standard library less known features. Have you ever found yourself writing complex code only to discover that Python has tools available within its library that could have made your job easier? Then this talk is for you!

#PyCon #PyConIe #PyConIe2023 #functools #itertools #doctest

Mia Bajić: The Standard Library Tour @ PyCon Ireland 2023

YouTube

@driscollis yet another thing in the #python standard library I've never seen or used. I wonder when one would use the functools.singledispatch over a set of if isinstance(..) elif isinstance(..)? The singledispatch feels like a bit of magic since going to the definition of the function does not show what it does and one has to go to Ctrl-F for all the @func.register's to find the implementation 🤔

#functools #pythonstandardlibrary

#Python’s #functools Module: Caching, Dispatching, and Other Higher-Order Operations. Explaining Python’s functools module, including caching, comparison utilities, function dispatching, and more.

https://thecodecadence.medium.com/pythons-functools-module-caching-dispatching-and-other-higher-order-operations-ad834620ad1a

Today I learnt about @cached_property in python

As a classically trained physicist, my natural style of programming is functional.

But in production-level code, we usually want a mix of classes and functions.

However, this can get awkward.

THE CHICKEN AND EGG ATTRIBUTE DILEMMA
Oftentimes, we'll calculate some properties for a class and set them as attributes. Maybe it's the mean and standard deviation for our data class in machine learning, for example.

But that'd mean we have to initialise our class, load the data at initialisation and calculate those statistics.

That can be a bit silly in many cases.

Especially when we're building a larger class with some extra utility, this can quickly devolve into creating a monster at __init__.

Read more… [https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/] (2 min remaining to read)

#Functools #Python #TodayILearned #MachineLearning

Find more here: https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/

Today I learnt about @cached_property in python

Write cleaner code and decoupled classes with cached properties.

Real-world Machine Learning
Today I learnt about @cached_property in python

Write cleaner code and decoupled classes with cached properties.

Real-world Machine Learning
🌗 函數式編程 HOWTO — Python 3.11.4 文件
➤ Python 的函數式編程特性
https://docs.python.org/3/howto/functional.html
本文介紹 Python 的函數式編程特性,包括迭代器、生成器、itertools 和 functools 等庫模塊。函數式編程將問題分解為一組函數,並鼓勵使用純函數,即只接受輸入並生成輸出,不修改內部狀態。函數式編程具有形式化可證明、模塊化、可組合、易於調試和測試等優點。
+ 很好的介紹了 Python 的函數式編程特性,讓我更好地理解了函數式編程的概念和優點。
+ 這篇文章很有用,尤其是對於那些想學習函數式編程的 Python 開發人員來說。
#Python #函數式編程 #iterators #generators #itertools #functools
Functional Programming HOWTO

Author, A. M. Kuchling,, Release, 0.32,. In this document, we’ll take a tour of Python’s features suitable for implementing programs in a functional style. After an introduction to the concepts of ...

Python documentation