-1

I have a file with lines of two integer separated by ','. I just want to store this integers from each line related together. example : file:

12,23
45,6545
12,89

I want to save 12 and 23 or 45 and 6545 both related together which I could call em 'both' or 'one by one' later .

Thank you

update, Dear @MaxU I have a file named 'A'

A:
36,89
65,84
52,999
1,7

each two numbers in one line are a pair and I want to use them together or separately in calculations ... .

ed1952
  • 1
  • 1

1 Answers1

0

This should do it.

nums = []
with open("yourfile.txt","r") as f:
     for line in f:
         nums.append(line)

Now, each line is stored together in an index of the array. If you want to access the values one by one, you can just iterate and split:

for i in nums:
    print(i.split(",")[0] + " " + i.split(",")[1])

To access them together, just go through the indexed of the array.

intboolstring
  • 6,891
  • 5
  • 30
  • 44