You can use a simple regular expression:
import re
a = "DEL MONTE Alfredo"
first, last = re.match(r'([A-Z ]+)\s+(.+)', a).groups()
or loop through a list of words and filter out all capital letters:
first = ' '.join(w for w in a.split() if w.isupper())
last = ' '.join(w for w in a.split() if not w.isupper())
In my personal opinion, "the most pythonic" === "the simplest."
source
share