Reading specific columns from a text file in python

前端 未结 6 566
一生所求
一生所求 2020-12-08 05:26

I have a text file which contains a table comprised of numbers e.g:

5 10 6

6 20 1

7 30 4

8 40 3

9 23 1

4 13 6

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 05:46

    You can use a zip function with a list comprehension :

    with open('ex.txt') as f:
        print zip(*[line.split() for line in f])[1]
    

    result :

    ('10', '20', '30', '40', '23', '13')
    

提交回复
热议问题