the first line is compiling a regular for later use.
I'll explain piece by piece :
r' ' : it for python raw strings for unconflicting regex
[ ] : are selectors to specify which characters and/or range of characters to find
A-Z: specify all upper case letters and a-z all lower case letters
+ : is a greedy meta-character which tells the regex engine to find 1 or more characters which match earlier criteria
lets see an example :http://docs.python.org/2/howto/regex.html
string = 'i_am doing**it ^&wrong 1234'
and we're using findall so it will well find all parts of the string that match our regex and return a list
list = ['i','am','doing','it','wrong']
and then join everything in the list with the blank string and return "iamdoingitwrong"
Although it is a little bit complicated since you don't about regex much but it is a lot more safer and short and frankly it will far more easy when you learn about regex
you can learn more about regex here : http://docs.python.org/2/howto/regex.html
you would probably be better off using simple regex. Here :
import redef only_alpha(text): regex = re.compile(r'[A-Za-z]+') ans = "".join(regex.findall(text)) return ans
it should probably do it if you have any confusion about the regex just ask i'll explain it to you