Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 26a698b

Browse filesBrowse files
feat: partial_function - Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords
1 parent 2e1e41f commit 26a698b
Copy full SHA for 26a698b

File tree

6 files changed

+10
-0
lines changed
Filter options

6 files changed

+10
-0
lines changed

‎ebook/chapters/third_party_chapters/timing.tex

Copy file name to clipboardExpand all lines: ebook/chapters/third_party_chapters/timing.tex
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ \subsection{range VS repeat}
5555
"Range" spend time: 0.01480103
5656
"Repeat" spend time: 0.01320004
5757
\end{lstlisting}
58+
59+
If you want to avoid passing the \lstinline{None} argument, you can create a new function called \lstinline{times}, which hides the \lstinline{None} argument.
60+
61+
\lstinputlisting[caption=partial\_function.py]{../standard_lib/partial_function.py}

‎ebook/python-snippets.epub

Copy file name to clipboard
143 Bytes
Binary file not shown.

‎ebook/python-snippets.mobi

Copy file name to clipboard
62 Bytes
Binary file not shown.

‎ebook/python-snippets.pdf

Copy file name to clipboard
1.54 KB
Binary file not shown.

‎standard_lib/README.md

Copy file name to clipboardExpand all lines: standard_lib/README.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ A collection of useful snippets using only the standard library.
3939
| open_browser_tab | Opens a new tab in a specified browser (and more) |
4040
| overwrite_dictionary | PEP 448 - overwriting dictionary of default values |
4141
| parse_query_string | Parse a query string |
42+
| partial_function | Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords |
4243
| pass_multiple_dicts | Unpack multiple dicts and pass them as keyword args to a function |
4344
| pathlib_relpath | `pathlib.Path` implementation of `os.relpath` (should never be used) |
4445
| port_scanner | Simple port scanner implementation using built-in packages |

‎standard_lib/partial_function.py

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from functools import partial
2+
from itertools import repeat
3+
4+
times = partial(repeat, None)
5+
min(random.random() for _ in times(100_000))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.