Skip to main content

Adds some useful methods on top of Python lists

Project description

Better Python Lists

Makes lists in Python better, by adding some useful methods.

Installation

pip install better-python-lists

Basic Usage

Compact

The compact method is inspired by Ruby's Array.compact. It removes all None elements from the List, returning a copy of the List.

from better_python_lists import List

my_list = List([1, None, 2, 3, 4, None, None, 5])
compact_list = my_list.compact()
print(compact_list)
# => [1, 2, 3, 4, 5]

You can also perform in-place compacting using the compacted method:

print(my_list)  # => [1, None, 2, 3, 4, None, None, 5]
my_list.compacted()
print(my_list)  # => [1, 2, 3, 4, 5]

If you want to filter out more than just None, you can pass in an optional filter list:

another_list = List([1, "None", 2, None, 3, "N/A"])
another_list.compacted(filter_list=[None, "None", "N/A"])
print(another_list)  # => [1, 2, 3]

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

better_python_lists-0.1.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

better_python_lists-0.1.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file better_python_lists-0.1.2.tar.gz.

File metadata

  • Download URL: better_python_lists-0.1.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.4.0

File hashes

Hashes for better_python_lists-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1b7160d6dc703024f0dd4c10fd377c7ee4aa30149978d2ad1cf369f780012028
MD5 86867020154f91f73375c8b0f9727a3d
BLAKE2b-256 df06e733b71e33ea8512c81492adf9d3f0475fb4039f6823363faa61f2364c1c

See more details on using hashes here.

File details

Details for the file better_python_lists-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for better_python_lists-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b192669bc953da20d13c784dfdd6a0d95cf53735050a7afb03646eabb988111
MD5 fcfc71402d74138c97ec4cabe2d42b02
BLAKE2b-256 f435c7b4baf64b36509a8004cce197e835a62cd84d80e7c824b6f4e856df0001

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