efficiently checking that string consists of one character in Python

后端 未结 8 1310
太阳男子
太阳男子 2020-11-29 01:03

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\')

8条回答
  •  抹茶落季
    2020-11-29 02:06

    You could convert to a set and check there is only one member:

    len(set("AAAAAAAA"))
    

提交回复
热议问题