To be specific, if I have string a: a = "uuuuuuuuuuuuuiuuuuu" and string b: b = "uuuuuuuuuuuuuuuu" and I want to check if the given string only contains one kind of character. In the first string, it contains another char called i, so it will return false. The string b it has only one kind, so it will return true.
Asked
Active
Viewed 58 times
0
Dwa
- 490
- 3
- 11
1 Answers
3
You can convert the string to a set and look at its length:
a = "uuuuuuuuuuuuuiuuuuu"
print(len(set(a)) == 1)
# False
b = "uuuuuuuuuuuuuuuu"
print(len(set(b)) == 1)
#True
Mark
- 84,957
- 6
- 91
- 136