Read file as a list of tuples

前端 未结 3 1490
慢半拍i
慢半拍i 2021-02-09 09:03

I want to read a text file using Python. My list must be like this:

mylist = [(-34.968398, -6.487265), (-34.969448, -6.488250),
          (-34.967364, -6.492370)         


        
3条回答
  •  清酒与你
    2021-02-09 09:46

    This code should do it:

    ifile=open("data/t2mG_00", "r")
    lines=ifile.readlines()
    data=[tuple(line.strip().split()) for line in lines]
    print(data[0])
    

提交回复
热议问题