Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes
Sponsored Reserved space — layout preview until AdSense is connected
Reference library

Python Code Samples

Copy-ready Python snippets by topic and difficulty — short, focused, and runnable in the browser editor.

4 matches
Sponsored Reserved space — layout preview until AdSense is connected
Files & data easy

Convert All Markdown Files in a Folder to HTML in Python

Batch convert every .md file in a folder to .html using the `markdown` library with the 'extra' extensions.

markdown html batch-conversion
Python
import os
import markdown
from pathlib import Path

def convert_md_folder_to_html(input_folder="markdown_files", output_folder="html_pages"):
    input_path = Path(input_folder)
    output_path = Path(output_folder)
    output_path.mkdir(exist_ok=True)
    
    for md_file in input_path.glob("*.md"):
        with open…
2 0 Open
Files & data medium

Find Duplicate Web Pages by Content Similarity in Python

Compute SHA-256 hashes of file contents to detect and report duplicate HTML pages or any files in a directory.

duplicate-detection hashing sha256
Python
import hashlib
import os
from collections import defaultdict

def get_file_hash(filepath):
    """Compute SHA-256 hash of file contents."""
    sha256 = hashlib.sha256()
    with open(filepath, 'rb') as f:
        for chunk in iter(lambda: f.read(4096), b''):
            sha256.update(chunk)
    return sha256.hexdiges…
2 0 Open
Files & data medium

How to Build a CSV Comparison Tool That Highlights Every Changed Cell in Python

Read two CSV files with DictReader, compare cell by cell, and return a list of dictionaries describing each changed cell using only the standard library.

csv comparison diff
Python
import csv
from pathlib import Path

def csv_cell_diff(file_a: str, file_b: str) -> list[dict]:
    rows_a = list(csv.DictReader(Path(file_a).open('r', newline='')))
    rows_b = list(csv.DictReader(Path(file_b).open('r', newline='')))
    if not rows_a or not rows_b:
        return []
    columns = list(rows_a[0].key…
2 0 Open
Automation & scripting medium

Automatically Generate Charts from CSV Files with One Command

Read a CSV file with headers, extract the first two numeric columns, and save a matplotlib line chart as a PNG image.

csv matplotlib charting
Python
import csv
import sys
from pathlib import Path
import matplotlib.pyplot as plt

def generate_chart(csv_path: str) -> None:
    """Read a CSV file with headers and plot the first two numeric columns."""
    data = []
    with open(csv_path, 'r', newline='') as f:
        reader = csv.reader(f)
        headers = next(re…
3 0 Open

Browse by section

Each section groups closely related Python snippets.

Guide: free Python code samples library

Copy-ready Python snippets for learners and developers

PythonSkillset code samples are short, focused examples organised by topic and difficulty. Every snippet is server-rendered HTML — readable by search engines and easy to copy. Open any sample, read the notes, copy the code, then press Try in editor to run it in the browser with Pyodide.

How to use this library

  1. Pick a topic section — strings, lists, files, functions, and more
  2. Open a sample, read How it works, and copy the code block
  3. Run it in the IDE, tweak values, then take a related quiz or tutorial lesson

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.