insomnihack

When sleep eludes, the keyboard beckons

Random Kung Fu Move Name Generator in 5 Lines of Python

November 17, 2012 Dale Leave a Comment

I love Python because of things like random.choice, a usefulĀ little method that allows you to create mission-critical functionality with very little code. For example, who doesn’t need a random Kung Fu move name at least once a week? I know I do. With Python, its a snap.

[python]

>>> from random import choice
>>> a = [‘flying’, ‘thunderous’, ‘crushing’]
>>> b = [‘hammer’, ‘eagle’, ‘snake’, ‘dragon’, ‘lotus’]
>>> c = [‘fist’, ‘kick’, ‘palm’, ‘strike’]
>>> ‘ ‘.join([choice(a), choice(b), choice(c)])
‘thunderous snake fist’

[/python]

Programming Python

Leave a Reply

Your email address will not be published. Required fields are marked *

About Me

Hi, my name's Dale, and this is my tech blog. Read More…

Search

Tags

blogging c# database Django documentation Email furniture git hacks htpc IPython Linux mac nas packaging PyCharm Python Roleplaying tools twitter unit tests virtualenv Visual Studio vmware Windows

Copyright © 2025 · Equilibre Theme on Genesis Framework · WordPress · Log in