Fading Coder

One Final Commit for the Last Sprint

Finding the Longest Common Prefix in an Array of Strings

The task is to identify the longest common prefix shared among all strings in a given array. For instance, with an input like ['abc', 'abcd', 'abd'], the result should be 'ab'. Approach 1: Brute Force Itertaion A straightforward method involves incrementally building prefixes and verifying each one...

JSON Schema Validation in Python: A Practical Guide

Installation First, install the required library: pip install jsonschema Validating Basic Data Types The fololwing example demonstrates validating an object with string and numeric fields: from jsonschema import validate definition = { "type": "object", "properties": {...

Building a CBOW Model from Scratch with Negative Sampling

import math import numpy as np import pandas as pd import random from docx import Document import re random.seed(0) pd.options.display.max_rows = None # --------------------------- Configuration parameters --------------------------- doc_path = r"simple_word.docx" learning_rate = 0.01 embe...

Understanding Python Generators and the Yield Statement

List comprehensions provide a convenient way to create lists in Python, but they come with a significant drawback: the entire list is stored in memory. For large datasets, this can quickly exhaust available resources. Consider a scenario where a list of one million items is created, but only the fi...

Python Built-In Higher-Order Functions Overview

Mapping Sequences with map() The map() function constructs an iterator that applies a given function to each item of an iterable. It transforms the data structure by passing every element through a processing logic. Conisder calculating the cubic value for a sequence of integers: def cube(val): retu...

Understanding Python Iterators and Generators for Efficient Collections Access

An iterator in Python provides a uniform way to traverse collections without exposing underlying structure. It captures the current location during traversal and proceeds strictly forward, never backward. Every iterator exposes two essential functions: iter() to obtain the object and next() to retri...

Converting HTTP Requests to cURL Commands with Python's curlify Library

The curlify library enables conversion of Python requests objects into executable cURL command strings. This functionality is particularly useful for debugging HTTP intercations and replicating API calls out side of Python environments. Installation is performed via pip: pip install curlify Once ins...

Implementing Different Server Models in Python

Single-Process Server Model import socket server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(('', 8000)) server_socket.listen(128) while True: client_socket, client_address = server_socket.accept()...

:Python Closures: Advanced Function State Management

Function Objects as First-Class Citizens def greet(): return "hello closure" print(greet) # <function greet at 0x000001F3A8B42E20> print(greet()) # hello closure Function names reference memory addresses containing executable code. The () operator trigggers execution at that address....

Python Data Structures and Algorithms: Practical Filtering, Sorting, and Tracking Techniques

Filtering Negative Numbers from a List Using list comprehension provides a clean, readable approach: from random import randint numbers = [randint(-10, 10) for _ in range(10)] positive_only = [n for n in numbers if n >= 0] print("Original:", numbers) print("Filtered:", positiv...