• Home
  • About
    • About The Coder
    • Language List
  • Code Rules
    • #1: Clarity Trumps Everything
    • #2: Source Code is for Humans
    • #3: Don’t Ignore Warnings
    • #4: Comment As You Go
    • #5: Always Use Parentheses
    • #6: Always Define Literals
    • #7: Never Repeat Yourself
  • CS-101
  • Python-101
  • Simple Tricks
  • Guestbook

The Hard-Core Coder

~ I can't stop writing code!

The Hard-Core Coder

Tag Archives: Python code

Elementary Cellular Automaton

28 Monday Apr 2025

Posted by Wyrd Smythe in Fun, Python

≈ 3 Comments

Tags

cellular automaton, Python code

For quite some time, I’ve wanted to write some Python code to implement and elementary cellular automaton. In particular, I wanted to “investigate” (play around with) the famous Rule 110, which is known to be Turing complete.

Despite the name, this has nothing to do with cellphones. It’s a 1D variation on the well-known 2D Game of Life designed by British mathematician John Conway. [See the John Conway’s Life and Life With Class posts for Python versions]

Continue reading →

Simple Python Tricks #15

31 Monday Mar 2025

Posted by Wyrd Smythe in Python

≈ 2 Comments

Tags

format method, format strings, Python code, regular expressions, Simple Tricks, str.translate, upside down characters

The political situation in the USA has dampened my mood and crashed my interest in this Simple Tricks series, but in hope of getting at least one post out this month (and on the very last day, no less), I’m going to revisit two topics I’ve written about before.

Back in Issue #8 of this series, I wrote about formatted output (to screen or file), especially using format strings (“f-strings”) and the format function and built-in method. In this issue, I’ll revisit the latter for a more sophisticated example. I also have some goodies for the str.translate method.

Continue reading →

Simple Python Tricks #14

17 Monday Feb 2025

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

comma sequence, Python code, Simple Tricks

This post was meant to be the final edition of Simple Tricks in 2024. My every-other-Monday schedule had it slotted for December 23rd. But I came down with a respiratory virus on the 22nd. The post wasn’t complete at that point, so I pushed publication to the following Monday, the 30th, but I was sick until well into the new year.

I ended up taking January off from the web (and computers in general), and it’s not until now that I’ve caught up with myself. In any event, I’m not sure how many more of these Simple Tricks posts I’ll do, but here’s one more.
Continue reading →

Simple Python Tricks #13

09 Monday Dec 2024

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Monty Hall problem, Python code, Simple Tricks, tail recursion

The last few posts in this Simple Tricks series were perhaps a bit less than simple, so this month, here at the end of the year, I’m going to take it easy and enjoy the season. (I hope you are doing so as well!)

I’ve put together a random grab bag of little bits and pieces of Python. Nothing too complicated. And in all honesty, probably nothing terribly interesting or that useful, either. But you may find some of the approaches helpful.

Continue reading →

Simple Python Tricks #12

25 Monday Nov 2024

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Python classes, Python code, Python descriptors, Python properties, Simple Tricks

The last two Simple Tricks posts looked at subclasses of built-in Python classes, in particular the tuple class, as well as the built-in class methods Python supports for any user-defined class. [See Simple Tricks #10 and Simple Tricks #11.]

This time I narrow the focus to real and virtual object attributes, the “x”, “y”, “z” elements of our vector objects. Python offers many ways to implement these, depending (as always) on what you want.

Continue reading →

Simple Python Tricks #11

11 Monday Nov 2024

Posted by Wyrd Smythe in Python

≈ 2 Comments

Tags

Python classes, Python code, Simple Tricks

Last time we looked at subclassing the Python built-in classes tuple, list, and dict with a focus on the built-in __new__ and __init__ methods (and never forget to include __str__ and/or __repr__ in your user-defined classes).

This time Simple Tricks explores many of the other built-in methods that help you create richly featured Python-aware objects. Specifically, we’ll focus on subclassing tuple to create (immutable) vector objects. A basic understanding of object-oriented programming is assumed.

Continue reading →

Simple Python Tricks #10

28 Monday Oct 2024

Posted by Wyrd Smythe in Python

≈ 4 Comments

Tags

Python classes, Python code, Simple Tricks, sub-class

Last time, Simple Tricks looked at some built-in Python functions. This time, we look at three built-in Python container classes, tuple, list, and dict, with a focus on designing useful sub-classes based on them.

We’ll explore the built-in __new__ and __init__ methods in detail along with some of the other built-in methods that help you to create rich new types. [The reader is assumed to be familiar with the basics of object-oriented programming.]

Continue reading →

Simple Python Tricks #9

14 Monday Oct 2024

Posted by Wyrd Smythe in Python

≈ 3 Comments

Tags

Python code, Simple Tricks

For many, fall means back to school, so for this blog I thought I’d return to Simple Tricks in Python. Fall also means Halloween for many, so hopefully these tricks will be treats, even if they do involve some very basic Python.

In this post, I explore some of Python’s more interesting and useful built-in functions, such as enumerate, sorted, reversed, map, and filter.

Continue reading →

The Python Turtle

30 Monday Sep 2024

Posted by Wyrd Smythe in Fun, Python

≈ 3 Comments

Tags

Python 101, Python code, turtle graphics

Some of you may have encountered the Logo programming language or one of its many offshoots. A memorable aspect of Logo was its use of turtle graphics — a form of vector graphics similar to pen plotters. Notably, turtle graphics features a relative drawing cursor.

Standard Python includes a turtle graphics module. It doesn’t have a huge production value (there’s no easy way to save an image, for instance), but it can be fun to play with.

Continue reading →

Python Tredoku Solver

16 Monday Sep 2024

Posted by Wyrd Smythe in Fun, Python

≈ 1 Comment

Tags

computer programming, puzzles, Python code, software design, Sudoku, Tredoku

I’ve never been particularly interested in puzzle games. Figuring out software has filled that niche for me (plenty puzzling enough). So, I’ve never done a Sudoku puzzle. Recently I read a post about Tredoku, which is a kind of three-dimensional Sudoku.

In that post was an unsolved Tredoku puzzle. I wasn’t tempted to try to solve it myself, but I did think it might be fun to see if I could write some Python to do it.

Continue reading →

← Older posts
Newer posts →
Follow The Hard-Core Coder on WordPress.com

The Posts

  • Python Tk Calculator App
  • Tk Windows in Python
  • Dual Numbers in Python
  • Python Decorators, more
  • Python Decorators, redux
  • Byte Multiplication Trick
  • Parsing Multipart Form Data
  • Simple Python Tricks #18
  • Simple Python Tricks #17
  • Simple Python Tricks #16

The Topics

  • Blog (4)
  • CS101 (37)
  • Fun (36)
  • Interesting (5)
  • Opinion (12)
  • Python (59)
  • Stories (15)

The Month

December 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Nov    

The Past

Posts

RSS Feed

Comments

RSS Feed

The Main Blog

Visit Logos con carne

Lots of wyrds... with meat!

The Author

Wyrd Smythe

Wyrd Smythe

The canonical fool on the hill watching the sunset and the rotation of the planet and thinking what he imagines are large thoughts.

View Full Profile →

Create a website or blog at WordPress.com

  • Subscribe Subscribed
    • The Hard-Core Coder
    • Already have a WordPress.com account? Log in now.
    • The Hard-Core Coder
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar