Splitting strings in Python without split()

后端 未结 8 714
醉话见心
醉话见心 2021-01-17 03:59

What are other ways to split a string without using the split() method? For example, how could [\'This is a Sentence\'] be split into [\'This\', \'is\', \'a\', \'Sentence\']

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 04:38

    sentence = 'This is a sentence'
    word=""
    for w in sentence :
        if w.isalpha():
            word=word+w
    
        elif not w.isalpha():
          print(word)
          word=""
    print(word)
    

提交回复
热议问题