Python Tips: Converting a string to a list of characters

Sometimes you may need to convert a string to a list of characters (for example you may want to calculate a hash value of the string using the folding method). If you want to break the string on spaces then you can simply use mystring.split() . For splitting the string into individual characters you can simply use list(mystring) .

However, in practice we almost never build our own hash function. Python has a default hash() function. For cryptography you might use the Hashlib module though.

Leave a Reply

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