2014-05-13 05:07:08 +00:00
|
|
|
# default separator (whitespace)
|
|
|
|
print("a b".rsplit())
|
|
|
|
#print(" a b ".rsplit(None))
|
|
|
|
#print(" a b ".rsplit(None, 1))
|
|
|
|
#print(" a b ".rsplit(None, 2))
|
|
|
|
#print(" a b c ".rsplit(None, 1))
|
|
|
|
#print(" a b c ".rsplit(None, 0))
|
|
|
|
#print(" a b c ".rsplit(None, -1))
|
|
|
|
|
2015-08-21 10:56:14 +00:00
|
|
|
# empty separator should fail (this actually delegates to .split())
|
2014-05-13 05:07:08 +00:00
|
|
|
try:
|
|
|
|
"abc".rsplit('')
|
|
|
|
except ValueError:
|
|
|
|
print("ValueError")
|
|
|
|
|
2015-08-21 10:56:14 +00:00
|
|
|
# empty separator should fail (error handled in .rsplit())
|
|
|
|
try:
|
|
|
|
'a a a a'.rsplit('', 5)
|
|
|
|
except ValueError:
|
|
|
|
print('ValueError')
|
|
|
|
|
|
|
|
# bad separator type
|
|
|
|
try:
|
|
|
|
'a a a a'.rsplit(1)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
2014-05-13 05:07:08 +00:00
|
|
|
# non-empty separator
|
|
|
|
print("abc".rsplit("a"))
|
|
|
|
print("abc".rsplit("b"))
|
|
|
|
print("abc".rsplit("c"))
|
|
|
|
print("abc".rsplit("z"))
|
|
|
|
print("abc".rsplit("ab"))
|
|
|
|
print("abc".rsplit("bc"))
|
|
|
|
print("abc".rsplit("abc"))
|
|
|
|
print("abc".rsplit("abcd"))
|
|
|
|
print("abcabc".rsplit("bc"))
|
|
|
|
print("abcabc".rsplit("bc", 0))
|
|
|
|
print("abcabc".rsplit("bc", 1))
|
|
|
|
print("abcabc".rsplit("bc", 2))
|
|
|
|
|
|
|
|
print("10/11/12".rsplit("/", 1))
|
|
|
|
print("10/11/12".rsplit("/", 2))
|
|
|
|
print("10/11/12".rsplit("/", 3))
|
|
|
|
print("10/11/12".rsplit("/", 4))
|
|
|
|
print("10/11/12".rsplit("/", 5))
|
|
|
|
|
|
|
|
print("/*10/*11/*12/*".rsplit("/*", 1))
|
|
|
|
print("/*10/*11/*12/*".rsplit("/*", 2))
|
|
|
|
print("/*10/*11/*12/*".rsplit("/*", 3))
|
|
|
|
print("/*10/*11/*12/*".rsplit("/*", 4))
|
|
|
|
print("/*10/*11/*12/*".rsplit("/*", 5))
|
|
|
|
|
|
|
|
print(b"abcabc".rsplit(b"bc", 2))
|
2017-06-02 03:08:18 +00:00
|
|
|
|
|
|
|
# negative "maxsplit" should delegate to .split()
|
|
|
|
print('abaca'.rsplit('a', -1))
|
|
|
|
print('abaca'.rsplit('a', -2))
|