Skip to main content

A collection of utility functions for harmonizing code.

Project description

codedharmony

A collection of utility functions to make your coding life easier.

Installation

pip install codedharmony

Python

import codedharmony 

or

from codedharmony import merge_dicts, safe_division, flatten_list, chunk_list

Examples

# Merging dictionaries
merged_dict = merge_dicts({'a': 1}, {'b': 2})
print(merged_dict)  # Output: {'a': 1, 'b': 2}

# Safe division
safe_result = safe_division(10, 0, default=0)
print(safe_result)  # Output: 0

# Flattening a nested list
nested_list = [1, [2, 3, [4, 5]], 6]
flat = flatten_list(nested_list)
print(flat)  # Output: [1, 2, 3, 4, 5, 6]

# Chunking a list
chunked_list = chunk_list([1, 2, 3, 4, 5], 2)
print(chunked_list)  # Output: [[1, 2], [3, 4], [5]]

# Finding duplicates in a list
duplicates = find_duplicates([1, 2, 2, 3, 4, 4, 5])
print(duplicates)  # Output: [2, 4]

# Getting unique elements
unique = unique_elements([1, 2, 2, 3, 4, 4])
print(unique)  # Output: [1, 2, 3, 4]

# Converting from camelCase
snake = camel_to_snake('camelCaseString')
print(snake)  # Output: camel_case_string

# Converting from snake_case to camelCase
camel = snake_to_camel('snake_case_string')
print(camel)  # Output: SnakeCaseString

# Checking if a string is a palindrome
is_pal = is_palindrome('A man, a plan, a canal: Panama')
print(is_pal)  # Output: True


# Counting occurrences
count = count_occurrences([1, 2, 2, 3, 3, 3, 4])
print(count)  # Output: {1: 1, 2: 2, 3: 3, 4: 1}

# Sorting dictionary by value
sorted_dict = sort_dict_by_value({'a': 3, 'b': 1, 'c': 2})
print(sorted_dict)  # Output: [('b', 1), ('c', 2), ('a', 3)]

# Removing None values from dictionary
clean_dict = remove_none_values({'a': 1, 'b': None, 'c': 3})
print(clean_dict)  # Output: {'a': 1, 'c': 3}

# Converting list to dictionary
data = ['apple', 'banana', 'cherry']
fruit_dict = list_to_dict(data, lambda x: x.upper())
print(fruit_dict)  # Output: {'APPLE': 'apple', 'BANANA': 'banana', 'CHERRY': 'cherry'}

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

codedharmony-0.1.4.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file codedharmony-0.1.4.tar.gz.

File metadata

  • Download URL: codedharmony-0.1.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for codedharmony-0.1.4.tar.gz
Algorithm Hash digest
SHA256 90dd5186112373d1e90e92c6a0f606ca5db1a9481a8a03a9959565a5e2f2b787
MD5 79bf96c220809b2ccd75896d1d9ad544
BLAKE2b-256 7c48ce6231ea0227696cfdc06a9107fd74c61f9f43b2a43bafd621e4df17c407

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