English description follows Japanese.
for i in range(∞):
...
のようなことができるツール
使い方
import range_inf
# 2乗が10を超えるまで繰り返す
for i in range_inf:
n = i ** 2
if n > 10: break
print(n) # -> 0\n1\n4\n9
ツール概要
- range(10)と同じような使用感で、無限に続くrange(無限大)を使いたいときのツール
- 上記の使用例のようにfor文等で使ってください
- いつ終了すべきかが予め分からないループを、whileではなくforで使えるため、簡単にインデックスが取得出来ます
詳細
- itertoolsに同様のものがありますが、最短の記述でサクッと使いたいときに便利です
- ネストして2重で使ったり、breakで中断した後再度使用しても、通常のgenerator等と異なり途中から始まることなく、リセットされて最初から始まるように作られています
Usage
import range_inf
# Repeat until the square exceeds 10
for i in range_inf:
n = i ** 2
if n > 10: break
print(n) # -> 0\n1\n4\n9
Overview
- A tool that provides an infinite
range(∞)with the same feel asrange(10) - Use it in
forloops as shown above - Ideal for loops where the exit condition isn't known in advance — allows index tracking using a
forloop instead ofwhile
Details
- While
itertoolsprovides similar functionality, this tool is convenient when you want the shortest and cleanest syntax - It can be nested or reused after a
break, and unlike typical generators, it always resets and starts from the beginning
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
range-inf-0.0.0.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file range-inf-0.0.0.tar.gz.
File metadata
- Download URL: range-inf-0.0.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c61c5e6b8a373a5132aa18b84321d2a33f54b85e2c41f23bf4428e87e60a3b01
|
|
| MD5 |
95c1acf45c37a0258d697377a79a6173
|
|
| BLAKE2b-256 |
a4fc71db521cb0ff3bac6a53c60f7e18c999cc19e72be6cb92a570594b726612
|
File details
Details for the file range_inf-0.0.0-py3-none-any.whl.
File metadata
- Download URL: range_inf-0.0.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5207b112c532b8146f7fd7206d5174e1ea96ef5da64d122f59ad6b157831a414
|
|
| MD5 |
fbb324e03cb58cdac24c7b7cba9db626
|
|
| BLAKE2b-256 |
0331c9d32b694a3c1d533b9cfc768862ddfeedfaa9789011b74e39ba2dee4629
|