Whittle it on down
DFS
nospam at dfs.com
Thu May 5 08:57:31 EDT 2016
On 5/5/2016 1:53 AM, Jussi Piitulainen wrote:
> Either way is easy to approximate with a regex:
>
> import re
> upper = re.compile(r'[A-Z &]+')
> lower = re.compile(r'[^A-Z &]')
> print([datum for datum in data if upper.fullmatch(datum)])
> print([datum for datum in data if not lower.search(datum)])
This is similar to Hansen's solution.
> I've skipped testing that the ampersand is between spaces, and I've
> skipped the period. Adjust.
Will do.
> This considers only ASCII upper case letters. You can add individual
> letters that matter to you, or you can reach for the documentation to
> find if there is some generic notation for all upper case letters.
>
> The newer regex package on PyPI supports POSIX character classes like
> [:upper:], I think, and there may or may not be notation for Unicode
> character categories in re or regex - LU would be Letter, Uppercase.
Thanks.
More information about the Python-list
mailing list