Sunday, January 25, 2015

Finding all Possible Combinations of Characters in a String

Here is a very simple but useful function I found here. It expects a string as a parameter and returns a list of all possible permutations of the letters. See the code by going to http://codepad.org/uLu0OvIX

The way the function works is pretty simple:

Thursday, January 1, 2015

Maketrans and translate

Today I learned a really cool Python feature and I thought I would share it with you. It is especially of interest to those who like use Python for ciphers and things like that.

The trick uses two functions, string.maketrans and str.translate. Together you can make a substitution cipher(http://en.wikipedia.org/wiki/Substitution_cipher) in only 8 lines of Python! Take a look at this code

A Beginners Guide to List Comprehensions

Most people think of list comprehensions as being a complex and unnecessary  part of Python. However, with a basic understanding of list comprehensions, many things that would take several lines of code to do take only one or two! If this short intro has convinced you that you need to learn about list comprehensions, read on!

Saturday, November 29, 2014

Awesome Python One-liners

Hi there! Today I thought I would show you a bunch of awesome python one-liners. Full disclosure: I did not write any of these myself. Some of them are from here and some of them are from here.