Found something useful? Don't forget to leave a comment!

Tuesday, July 13, 2010

1337 tip: Alphabetize a String in Python with a One-liner

Let’s say you have a string of letters that needs to be alphabetized – a string of nucleotide bases, for example.

Original string: “TA”
New alphabetized string: “AT”

Code: newString = ‘’.join(sorted(myString))


1 comment:

PeterVermont said...

Perfect. Exactly my situation -- got a genotype file which for some strange reason has the heterozygote as both TA and AT.