0

I have a .txt file with entries separated by a newline and a comma, alternating.

x = file_1.read().split("\n")
...
x = ['10,0902', '13897,00641']

how can I also delimit by a comma? .split("\n" and ",") does not seem to work

MaunaKea
  • 43
  • 7

1 Answers1

0

.split("\n" and ",") is the same as .split(True) which doesn't make much sense.

You'd want to use re.split so you can split by a regex:

import re

string = '1,2\n3,4'

print(re.split(r'(?:\n|,)', string))
#  ['1', '2', '3', '4']
DeepSpace
  • 78,697
  • 11
  • 109
  • 154