我的例句是' _'分离器:
s = "This_is_some_sentence_ID"
splited = s.split('_')
print(splited)
这就像['这',','某些','句子',' ID&# 39]
但是我怎样才能得到两个部分,比如[' This_is_some_sentence',' ID']?
答案 0 :(得分:4)
您可以使用rsplit:
In [3]: s = "This_is_some_sentence_ID"
In [4]: splited = s.rsplit('_', 1)
In [5]: print(splited)
['This_is_some_sentence', 'ID']