14

GitHub - chuanconggao/extratools: 100+ extra higher-level functional tools beyon...

 6 years ago
source link: https://github.com/chuanconggao/extratools
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

PyPI version PyPI pyversions PyPI license

100+ extra functional tools that go beyond standard library's itertools, functools, etc. and popular third-party libraries like toolz, fancy, and more-itertools.

  • Like toolz and others, most of the tools are designed to be efficient, pure, and lazy. Several useful yet non-functional tools are also included.

  • While toolz and others target basic scenarios, most tools in this library target more advanced and complete scenarios.

  • A few useful CLI tools for respective functions are also installed. They are available as extratools-[funcname].

Full documentation is available here.

Plans

This library is under active development, and new tools are added on regular basis.

Besides other interesting ideas, I am planning to make the following updates in recent days/weeks/months.

  • Add dicttools.unflatten and jsontools.unflatten.

  • Add trie and suffixtree (according to generalized suffix tree).

  • Update seqtools.commonsubseq, seqtools.commonsubseqwithgap, seqtools.align, and strtools.commonsubstr to support more than two sequences/strings.

Index of Available Tools

  • Functions:

debugtools dicttools jsontools mathtools misctools printtools rangetools recttools seqtools settools sortedtools stattools strtools tabletools

  • Data Structures:

defaultlist disjointsets segmenttree

  • CLI Tools:

dicttools.remap jsontools.flatten stattools.teststats

Examples

Here are three examples out of dozens of our tools.

list(compress([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]))
# [(1, 1), (2, 2), (3, 3), (4, 4)]
list(gaps(
    [(-inf, 0), (0.1, 0.2), (0.5, 0.7), (0.6, 0.9)],
    (0, 1)
))
# [(0, 0.1), (0.2, 0.5), (0.9, 1)]
flatten(json.loads("""{
  "name": "John",
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}"""))
# {'name': 'John',
#  'address.streetAddress': '21 2nd Street',
#  'address.city': 'New York',
#  'phoneNumbers[0].type': 'home',
#  'phoneNumbers[0].number': '212 555-1234',
#  'phoneNumbers[1].type': 'office',
#  'phoneNumbers[1].number': '646 555-4567',
#  'children': [],
#  'spouse': None}

Installation

This package is available on PyPI. Just use pip3 install -U extratools to install it.

Other Libraries

The following libraries are highly recommended to use together with extratools.

toolz sortedcontainers


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK