Skip to content

Instantly share code, notes, and snippets.

@specialorange
Created November 4, 2025 01:41
Show Gist options
  • Select an option

  • Save specialorange/3323105ee14f056437638f0cbc4123a0 to your computer and use it in GitHub Desktop.

Select an option

Save specialorange/3323105ee14f056437638f0cbc4123a0 to your computer and use it in GitHub Desktop.
1. Using List Methods
# Managing today's service queue
# Type: list
service_queue = ["Tire Rotation", "Flat Repair", "Balance", "Alignment"]
# Add new service to the end
service_queue.append("Tire Replacement")
print(f"Queue: {service_queue}")
# Insert urgent service at front
service_queue.insert(0, "Emergency Flat Repair")
print(f"Updated queue: {service_queue}")
# Remove completed service
# Type: str (string - a single completed service)
completed = service_queue.pop(0)
print(f"Completed: {completed}")
# Count how many rotations scheduled
# Type: int (integer - a whole number)
rotation_count = service_queue.count("Tire Rotation")
print(f"Rotations scheduled: {rotation_count}")
# Sort tire sizes in stock
# Type: list
tire_sizes = ["P215/65R15", "P195/60R15", "P225/60R16", "P205/55R16"]
tire_sizes.sort()
print(f"Sorted sizes: {tire_sizes}")
# Reverse the list
tire_sizes.reverse()
print(f"Reversed: {tire_sizes}")
2. Combining Dictionaries
# Inventory from two suppliers
# Type: dict (dictionary - key: tire size, value: quantity)
supplier_a = {
"P215/65R15": 12,
"P195/60R15": 8,
"P225/60R16": 15
}
# Type: dict
supplier_b = {
"P225/60R16": 10, # We have this from both suppliers
"P205/55R16": 20,
"LT245/75R16": 6
}
# Combine inventories (Python 3.9+)
# Type: dict
total_inventory = supplier_a | supplier_b
print(f"Combined inventory: {total_inventory}")
# Or add quantities for matching sizes
# Type: dict (a copy of supplier_a)
combined = supplier_a.copy()
for size, qty in supplier_b.items():
combined[size] = combined.get(size, 0) + qty
print(f"Total quantities: {combined}")
# Update customer record with new service
# Type: dict
customer = {"name": "John Doe", "phone": "555-1234"}
# Type: dict
service_info = {"last_service": "2024-11-01", "mileage": 45000}
customer.update(service_info)
print(f"Customer record: {customer}")
3. Using Tuple Methods
# Tire specifications (immutable data - won't change)
# Type: tuple (like a list but cannot be changed after creation)
tire_spec = ("P215/65R15", "All-Season", 32, "Michelin") # size, type, PSI, brand
# Access specific values
# Type: str
size = tire_spec[0]
# Type: int
recommended_psi = tire_spec[2]
print(f"Size: {size}, Recommended PSI: {recommended_psi}")
# Find position of data
# Type: int (the index position)
brand_position = tire_spec.index("Michelin")
print(f"Brand is at position: {brand_position}")
# Count occurrences (useful for checking data)
# Type: tuple
tire_orders = ("P215/65R15", "P225/60R16", "P215/65R15", "P215/65R15")
# Type: int
popular_size_count = tire_orders.count("P215/65R15")
print(f"P215/65R15 ordered {popular_size_count} times")
# Multiple tire specs
# Type: list of tuples
inventory_specs = [
("P215/65R15", "All-Season", 32),
("P225/60R16", "Performance", 35),
("LT245/75R16", "All-Terrain", 45)
]
# Type: str, str, int (unpacking the tuple in the loop)
for size, tire_type, psi in inventory_specs:
print(f"{size} - {tire_type} - {psi} PSI")
4. Arranging and Presenting Data Using Dictionaries
# Organized inventory by brand and size
# Type: dict (nested dictionary - dict inside a dict inside a dict)
tire_inventory = {
"Michelin": {
"P215/65R15": {"quantity": 12, "price": 145.00},
"P225/60R16": {"quantity": 8, "price": 165.00}
},
"Goodyear": {
"P215/65R15": {"quantity": 10, "price": 135.00},
"P205/55R16": {"quantity": 15, "price": 155.00}
}
}
# Access nested data
# Type: int
michelin_215_qty = tire_inventory["Michelin"]["P215/65R15"]["quantity"]
print(f"Michelin P215/65R15 in stock: {michelin_215_qty}")
# Customer service records
# Type: dict (nested dictionary with customer IDs as keys)
customers = {
"CUST001": {
"name": "John Doe",
"vehicle": "2018 Honda Civic",
"services": ["Rotation", "Balance"],
"last_visit": "2024-10-15"
},
"CUST002": {
"name": "Jane Smith",
"vehicle": "2020 Ford F-150",
"services": ["Replacement", "Alignment"],
"last_visit": "2024-11-01"
}
}
# Display all customers and their last service
# Type: str (cust_id), dict (info)
for cust_id, info in customers.items():
print(f"{info['name']} - Last visit: {info['last_visit']}")
print(f" Services: {', '.join(info['services'])}\n")
5. Creating Intersections of Elements in a Collection
# Tire sizes currently in stock
# Type: set (collection of unique items, no duplicates allowed)
in_stock = {"P215/65R15", "P225/60R16", "P205/55R16", "LT245/75R16"}
# Tire sizes a customer needs
# Type: set
customer_needs = {"P215/65R15", "P195/60R15", "P225/60R16"}
# Find what we have that matches customer needs
# Type: set (intersection - items in both sets)
available_for_customer = in_stock & customer_needs
print(f"We have these sizes for customer: {available_for_customer}")
# Find what customer needs that we don't have
# Type: set (difference - items in customer_needs but not in_stock)
need_to_order = customer_needs - in_stock
print(f"Need to order: {need_to_order}")
# Multiple mechanics' certifications
# Type: set
mike_certs = {"Tire Installation", "Wheel Alignment", "TPMS Service"}
# Type: set
sarah_certs = {"Tire Installation", "Suspension", "Wheel Alignment"}
# Type: set
tom_certs = {"Tire Installation", "Brake Service", "Oil Change"}
# Find common certifications
# Type: set (intersection of all three sets)
common_skills = mike_certs & sarah_certs & tom_certs
print(f"All three can do: {common_skills}")
# Find all unique certifications in the shop
# Type: set (union - combines all items from all sets)
all_skills = mike_certs | sarah_certs | tom_certs
print(f"Shop capabilities: {all_skills}")
# Popular tire brands carried by both stores
# Type: set
store_a_brands = {"Michelin", "Goodyear", "Bridgestone", "Cooper"}
# Type: set
store_b_brands = {"Michelin", "Pirelli", "Goodyear", "Continental"}
# Type: set (intersection)
shared_brands = store_a_brands.intersection(store_b_brands)
print(f"Both stores carry: {shared_brands}")
Bonus: Combined Real-World Example
# Complete shop management example
def daily_report():
# Today's completed services
# Type: list
services = ["Rotation", "Flat Repair", "Balance", "Replacement", "Rotation"]
# Inventory updates
# Type: dict (key: tire size, value: quantity)
starting_inventory = {"P215/65R15": 20, "P225/60R16": 15}
# Type: dict
sold_today = {"P215/65R15": 4, "P225/60R16": 2}
# Update inventory
# Type: dict (copy of starting_inventory)
current_inventory = starting_inventory.copy()
# Type: str (size), int (qty)
for size, qty in sold_today.items():
current_inventory[size] -= qty
# Service statistics
# Type: int
rotation_count = services.count("Rotation")
# Type: int
total_services = len(services)
# Print report
print("=== DAILY SHOP REPORT ===")
print(f"Total services completed: {total_services}")
print(f"Tire rotations: {rotation_count}")
print("\nInventory Status:")
# Type: str (size), int (qty)
for size, qty in current_inventory.items():
print(f" {size}: {qty} tires")
if qty < 10:
print(f" ⚠️ LOW STOCK - Reorder soon!")
daily_report()
Quick Reference Guide for the Student
# PYTHON DATA TYPES CHEAT SHEET FOR TIRE MECHANICS
# Type: list - Ordered, changeable, allows duplicates
# Use for: Service queues, tire sizes, work orders
example_list = ["Rotation", "Balance", "Alignment"]
# Type: dict - Key-value pairs, unordered, changeable
# Use for: Inventory (size: quantity), customer info, pricing
example_dict = {"P215/65R15": 12, "P225/60R16": 8}
# Type: tuple - Ordered, unchangeable, allows duplicates
# Use for: Tire specs that won't change, coordinates
example_tuple = ("P215/65R15", "All-Season", 32)
# Type: set - Unordered, unchangeable items, NO duplicates
# Use for: Unique certifications, brands in stock, comparing inventories
example_set = {"Michelin", "Goodyear", "Bridgestone"}
# Type: str - Text/string
example_str = "Tire Rotation"
# Type: int - Whole numbers
example_int = 42
# Type: float - Decimal numbers
example_float = 145.99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment