例如:
noise
以及如何使其成为
slow_bell
如何在不导入任何内容的情况下有效地执行此操作?
答案 0 :(得分:1)
假设您知道这可能有用的单词的长度(您需要更新lengths
元组):
my_string='ONETWOTHREEFOURFIVESIXSEVENEIGHTNINETEN'
lengths = (3, 3, 5, 4, 4, 3)
words = []
start = 0
for i in lengths:
words.append(my_string[start:start+i])
start += i
print(words) # ['ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX']
答案 1 :(得分:1)
lengths = (3, 3, 5, 4, 4, 3)
it = iter('ONETWOTHREEFOURFIVESIXSEVENEIGHTNINETEN')
words = (''.join(next(it) for _ in range(length)) for length in lengths)
答案 2 :(得分:0)
为简单起见,您可以使用match()
方法。但在此之前,您需要具有与my_string
的输出相匹配的值,如:
var my_string='ONETWOTHREEFOURFIVESIXSEVENEIGHTNINETEN';
var one = "ONE";
var array = [];
if(string.match(one)) array.push(one);