从不同长度的字符串中收集最后一个词以进行过滤、自动标记和列填充?

Collect last word from varied length string for filtering, auto labeling and column population?

这几天我一直在寻找和阅读有关如何从不同长度的字符串中收集最后一个单词的信息。我发现了很多关于如何 collect/split 最后一个词的帖子,但是 none 我读过的内容解决了不同长度的问题。

我想将此功能用于字段计算器或标签表达式界面中的列填充、自动标签和内容过滤。

字符串示例:Morgan County, Johnson Parrish, John Brown County, Rick de la Rosa City, Big Wild life Area。

输出示例:县、教区、市、地区

我尝试过的任何方法都没有 100% 奏效。下面的代码几乎可以工作,并且如果我所有的字符串都是两个字长也可以工作:s.split( " " )[1:][0]

我正在使用 arcmap 10.2 / python

这个怎么样:

# example comma separated string ending with a period
s = "Morgan County, Johnson Parrish, John Brown County, Rick de la Rosa City, Big Wild life Area."

# output list
out = []

for pair in s.replace('.', '').split(', '):
    out.append(pair.split(' ')[-1])

print out

结果为:['County'、'Parrish'、'County'、'City'、'Area']