How would I read only the first word of each line of a text file?

前端 未结 6 1246
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 22:17

I wanted to know how I could read ONLY the FIRST WORD of each line in a text file. I tried various codes and tried altering codes but can only manage to read whole lines from a

6条回答
  •  孤独总比滥情好
    2021-02-04 23:19

    You are using split at the wrong point, try:

    for line in f:
        QuizList.append(line.split(None, 1)[0]) # add only first word
    

提交回复
热议问题