Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

intersperse-0.1.0a0-py2.py3-none-any.whl (3.0 kB view details)

Uploaded Python 2Python 3

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

Hashes for intersperse-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 36145defb359017323111aad1401b909227c186b9d6b9ff6b6394db9f7a29e2d
MD5 111a6c479d069a06e52974c2eec98985
BLAKE2b-256 16c7f53ebb5a1dd3984e0d17911ae7cb7e8f17c6ca23410a7d5d752597c25676

See more details on using hashes here.

File details

Details for the file intersperse-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for intersperse-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d5a288f260bae0660c848c5cc423283af3832f5d0d3b0cea205fc1d15adc9cd1
MD5 0b1e64ceeaffa92878c436483135997e
BLAKE2b-256 e8da7e3c4eef76d0c6da31449f7ce890f52b8a03bf76382cc68cf80009ae7e2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page