0

If i have a text file such as:

"1,2,3,4,5 1 2 3 4 5
1
2
3
4
5"

How do i account for all of these different ways my numbers are separated if I am appending them to the same list?

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
  • 2
    `s.replace(',',' ').split()` – dirck Oct 24 '21 at 21:43
  • 1
    Regex split https://docs.python.org/3/library/re.html?highlight=split#re.split – DisappointedByUnaccountableMod Oct 24 '21 at 21:45
  • numbers = line.replace(","," ","\n").split() returns 'str' object cannot be interpreted as an integer. Additionally this has to be done without importing any modules. – Anther Eros Oct 24 '21 at 21:50
  • No where in that line of code are the characters of that string being interpreted as integers. You should see [ask] and post about the actual code you’re having issues with – Sayse Oct 24 '21 at 21:53
  • the last post was directed at dirck's suggestions of s.replace(',',' ').split() as a solution; however i added the \n character – Anther Eros Oct 24 '21 at 22:00
  • `.replace(","," ","\n")` isn't valid. Third argument would be max count and you're passing a string. split with no arguments handles the end of line. – dirck Oct 24 '21 at 22:24

0 Answers0