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:
Sunday, January 25, 2015
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.
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!