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\')
Interesting answers so far. Here's another:
flag = True for c in 'AAAAAAAfAAAA': if not c == 'A': flag = False break
The only advantage I can think of to mine is that it doesn't need to traverse the entire string if it finds an inconsistent character.