Adding the method find() to list - Ideas - Discussions on Python.org
May 6, 2020 ... ... write buggy code. So we're not likely to add new functions that act like this. On the other hand, we won't remove functions that people ...
May 6, 2020 ... ... write buggy code. So we're not likely to add new functions that act like this. On the other hand, we won't remove functions that people ...
Apr 10, 2025 ... Noticed a pattern of repeating a type annotation in functions returning a bit verbose generic container and having a way to duplicate the ...
For example, the type list[Any] is not equivalent to list[int]. Maybe you don’t really mean “equivalent types”. Perhaps you instead mean that the first argument should establish an implied upper bound constraint (which would be consistent with my point about the LSP and subtypes).
Aug 29, 2023 · The .get () calls allow me to write a somewhat fluent and safe getter for the nested objects. But this blows up if the list is empty. To work around that, I have to store in a variable and then either check the length of the list or wrap the indexing in a try/except. If I’m using a variable index instead of a literal 0, then I need to use try/except because of negative indexes. Maybe look at ...
Oct 11, 2023 ... As a scientific computing practitioner, I usually write sequential code and debug it in Jupyter. Once I complete the target, I encapsulate ...
Discussions on Python.org. Dynamic evaluation of function argument list initializer. Ideas. zhangyx (Yuxuan Zhang).While the not-yet-initialized object also depends on the function itself. This will throw “attribute not found” because argument list is immediately evaluated
Sep 20, 2023 · Every time I have trouble typing something in Python, it’s something others have needed before me, but hasn’t been implemented or designed yet (or has been implemented in a underpowered proto-state for years), and it’s impossible to correctly type my API without hundreds of lines of repetition or writing a code generator.
Jul 2, 2022 ... Ok, it was me, who recently pointed out that comprehensions should not be misused as an alternative way how to write a for loop.
May 26, 2024 · The you just want to iterate over B, comparing its keys against your collection Akeys. For example, code like this: for item in B: Bkey = transaction_key (item) if Bkey in Akeys: print ("found", item) Now, that just prints these out as matched. I’ll let you try to write code to collect the matching items into a list.
Jan 15, 2024 ... I've got a function where an argument is a dict[str, int | list[int]] , and I want to replace int with a type variable.
Python is not a purely functional programming language, and though it pains me sometimes, I will prefer an imperative style over a functional one in places where it just fits the language better. A good example are the built-in collection types (list, set, dict).
Aug 7, 2024 · For example, a developer unfamiliar with the context might mistakenly alter the type in the function signature without realizing it’s intended to correspond to the name attribute in the Person class. Moreover, establishing a direct relationship between the function argument type and the existing class attribute enhances code clarity.
Jan 5, 2026 ... That said, if AST-based type annotations get ... function definitions by allowing parenthesized parameter lists, type parameters and return type ...
Sep 27, 2023 · I would like to implement a function that returns a new type. And the returned type should be compatible with static type checkers. The initial idea I had was for the function to have a -> type return. However, this does not work because type checkers consider the assigned value to be a variable. The following code snippet illustrates it: def create_custom_type(name: str, **kwargs) -> type ...
Aug 19, 2023 ... ... type alias for a function (str) -> T StrConv = Callable[[str], _T_data] # split type signatures, otherwise the typer checker can't catch ...