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.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to