Skip to main content

This is a utility library that extends Python's list operations.

Project description

ExtList

PyPI version PyPI - Python Version GitHub

This library was created to improve the quality of code through list operations. It allows commonly written list comprehension operations to be called as methods and enables lists to be treated more abstractly than the built-in list.

Using this library reduces the number of times list comprehensions need to be written, resulting in improved overall code readability and searchability.

More information -> Docs: ExtList

Installation

pip install ext-list

Examples

Below are some examples of features of this library.

Note: In the following examples, the Person class is defined as follows.

(class Person)
>>> class Person:
...     def __init__(self, name, age):
...         self.__name = name
...         self.__age = age
...
...     def introduce(self):
...         return f'{self.name} is {self.age} years old.'
...
...     def get_age_n_years_ago(self, n: int) -> int:
...        return self.age - n
...
...     @property
...     def name(self):
...         return self.__name
...
...     @property
...     def age(self):
...         return self.__age
...
...     def __repr__(self):
...         return f'Person(\'{self.name}\', {self.age})'
...
  • Extract values

    >>> person_dicts = ExtList([{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}])
    >>> person_dicts.extract('name')
    ['Alice', 'Bob']
    
    >>> persons = ExtList(Person('Alice', 25), Person('Bob', 30))
    >>> persons.extract(Person.name)
    ['Alice', 'Bob']
    
    >>> persons.extract('name')
    ['Alice', 'Bob']
    
    >>> persons.extract(Person.introduce)
    ['Alice is 25 years old.', 'Bob is 30 years old.']
    
    >>> persons.extract(Person.get_age_n_years_ago, 5)
    [20, 25]
    
  • Get matched objects

    >>> persons = ExtList([{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}])
    >>> persons.equals('name', 'Alice')
    [{'name': 'Alice', 'age': 25}]
    
    >>> persons = ExtList(Person('Alice', 25), Person('Bob', 30))
    >>> persons.equals(Person.name, 'Alice')
    [Person('Alice', 25)]
    
    >>> persons.equals(Person.introduce, 'Bob is 30 years old.')
    [Person('Bob', 30)]
    
  • Convert list to dict

    >>> persons = ExtList([Person('Alice', 25), Person('Bob', 30)])
    >>> persons.to_dict(Person.name)
    {'Alice': Person('Alice', 25), 'Bob': Person('Bob', 30)}
    
  • Convert list to dict with complex keys

    >>> persons = ExtList([Person('Alice', 25), Person('Bob', 30)])
    >>> persons.to_dict_with_complex_keys([Person.name, Person.age])
    {('Alice', 25): Person('Alice', 30),
    ('Bob', 30): Person('Bob', 25)}
    

See the Docs: ExtList for more examples !

requirements

typing_extensions

License

MIT license

Author

Sakaguchi Ryo (@GuriTech)

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

ext-list-1.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

ext_list-1.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file ext-list-1.1.1.tar.gz.

File metadata

  • Download URL: ext-list-1.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0a6

File hashes

Hashes for ext-list-1.1.1.tar.gz
Algorithm Hash digest
SHA256 147019c34b0cccef6c771f5f5e9a949c4f90edd09984438ae46e632f5a62e8a3
MD5 0a2d5704f1d746769a1a1397ecf87d2c
BLAKE2b-256 1365b287efa84c2e25d1c272ba8fc7f13f0266fd9982a963244b1b4099a67f68

See more details on using hashes here.

File details

Details for the file ext_list-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: ext_list-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0a6

File hashes

Hashes for ext_list-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 927c2b0a6c1a440323c835b3cf2e7410e9ce828a99acec9efc676255859256c5
MD5 c2c03734f28d55a75e68c4c1cf2197b8
BLAKE2b-256 becc5a4c86e2efe8bf9157ca2202b2d758bf7f9ff659b10bfd4ef897b6ed1a29

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