read file into array separated by paragraph Python

后端 未结 7 965
半阙折子戏
半阙折子戏 2021-02-08 22:11

I have a text file, I want to read this text file into 3 different arrays, array1 array2 and array3. the first paragraph gets put in array1, the second paragraph gets put in arr

7条回答
  •  死守一世寂寞
    2021-02-08 22:35

    Because I feel like showing off:

    with open('data.txt') as f:
        f = list(f)
        a, b, c = (list(__import__('itertools').islice(f, i, None, 3)) for i in range(3))
    

提交回复
热议问题