What is an efficient way to check that a string s in Python consists of just one character, say \'A\'? Something like all_equal(s, \'A\')
s
\'A\'
all_equal(s, \'A\')
Try using the built-in function all:
all(c == 'A' for c in s)
Adding another solution to this problem
>>> not "AAAAAA".translate(None,"A") True