Skip to main content

Simple utility functions for KEC's Intro To Programming: Python Course

Project description

KEC ITP: Python Util Functions

Functions

kecutil.reduce(cb(cur, val), list, default)

Reduce is used to reduce a list to one value. This is commonly useful when finding the longest string for example

from kecutil import reduce


strings = ["ab", "acb", "abcdef", "abd"]
longestString = reduce(lambda x, y: x if len(x) > len(y) else y, strings, "")

print(longestString) # "abcdef"

kecutil.clearConsole()

Clears the console window

kecutil.clamp(value: int,length=2)

Clamps a float to have the same number of decimals as the length Returns a new float

from kecutil import clamp


number = 100.12345
clampedTwo = clamp(number)
clampedThree = clamp(number, 3)

print(clampedTwo) # 100.12
print(clampedThree) # 100.123
print(type(clampedTwo)) # <class 'float'>
print(type(clampedThree)) # <class 'float'>

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

kecutil-0.0.7.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file kecutil-0.0.7.tar.gz.

File metadata

  • Download URL: kecutil-0.0.7.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for kecutil-0.0.7.tar.gz
Algorithm Hash digest
SHA256 34ce4d94557a3c4b94cebb0e87469b630407fc0f07c6b1888c54bd8a0a74e787
MD5 3c95759da57afae91350bf1be50474e3
BLAKE2b-256 836444aacde5ea85482f646cad3d2c7db7371a6a9739665244545554b67ae7f2

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