Python, print delimited list

前端 未结 8 1397
小鲜肉
小鲜肉 2020-12-02 16:55

Consider this Python code for printing a list of comma separated values

for element in list:
    print element + \",\",

What is the preferr

8条回答
  •  伪装坚强ぢ
    2020-12-02 17:26

     def stringTokenizer(sentense,delimiters):
         list=[]
         word=""
         isInWord=False
         for ch in sentense:
             if ch in delimiters:
                 if isInWord: # start ow word
                     print(word)
                     list.append(word)
                     isInWord=False
             else:
                 if not isInWord: # end of word
                     word=""
                     isInWord=True
                 word=word+ch
         if isInWord: #  end of word at end of sentence
                 print(word)
                 list.append(word)
                 isInWord=False
         return list
    

    print (stringTokenizer(u"привет парни! я вам стихами, может быть, еще отвечу",", !"))

提交回复
热议问题