I know that regex is the way to go here but I am woeful at writing regex expressions. I have a file where each line looks like this: "defenders\t2\n" and I want to remove the \t and the \n and put the word "defenders" into the [0] of my multidimensional list and put the number "2" in the [1] of my list. Is there an easy regex way to do this in python?
import re
d = []
with open("somefile.txt") as f:
for line in f:
word = re.search()
rank = re.search()
d.append([word][rank])
This is what I am trying but I do not know how to make it work. Thanks for the help.