I am trying to create a script that concatenates values in files into columns. But unfortunately I get an error: "TypeError: can only concatenate list (not" str ") to list"
What am I doing wrong?
import re inputList = [] for file in ['text1.txt','text2.txt']: with open(file,'r') as infile: k = 0 for line in infile: i = 0 if i < len(inputList) and k: inputList[i].extend(re.sub('[^A-Za-z0-9,]+', '', line).split(",")) else : inputList.append(re.sub('[^A-Za-z0-9,]+', '', line).split(",")) i += 1 k = 1 print(inputList) with open('text3','w') as outfile: for line in inputList: outfile.write(line + '\n')
https://stackoverflow.com/questions/65839209/typeerror-can-only-concatenate-list-not-str-to-list-create-a-script-that-co January 22, 2021 at 12:13PM
没有评论:
发表评论