A simple Python generator that yields elements from an iterable, inserting a separator value between each element.
Project description
intersperse
A simple Python generator that yields elements from an iterable, inserting a separator value between each element.
Installation
pip install intersperse
Usage
# coding=utf-8
from intersperse import intersperse
# Intersperse zeros between numbers
print(list(intersperse([1, 2, 3], 0)))
# Output: [1, 0, 2, 0, 3]
# Works with any iterable
print(list(intersperse('abc', '-')))
# Output: ['a', '-', 'b', '-', 'c']
# Edge cases
print(list(intersperse([], 0)))
# Output: []
print(list(intersperse([1], 0)))
# Output: [1]
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
intersperse-0.1.0a0.tar.gz
(2.7 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 intersperse-0.1.0a0.tar.gz.
File metadata
- Download URL: intersperse-0.1.0a0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36145defb359017323111aad1401b909227c186b9d6b9ff6b6394db9f7a29e2d
|
|
| MD5 |
111a6c479d069a06e52974c2eec98985
|
|
| BLAKE2b-256 |
16c7f53ebb5a1dd3984e0d17911ae7cb7e8f17c6ca23410a7d5d752597c25676
|
File details
Details for the file intersperse-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: intersperse-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a288f260bae0660c848c5cc423283af3832f5d0d3b0cea205fc1d15adc9cd1
|
|
| MD5 |
0b1e64ceeaffa92878c436483135997e
|
|
| BLAKE2b-256 |
e8da7e3c4eef76d0c6da31449f7ce890f52b8a03bf76382cc68cf80009ae7e2f
|