I have text file with data like below:
"id":0
"value1":"234w-76-54"
"id":1
"value1":"2354w44-7-54"
I want to have these data in csv file. I tried with below code, but this is writing each ids and value1 as list in csv file.
with open("log.txt", "r") as file:
file2 = csv.writer (open("file.csv", "w", newline=""), delimiter=",")
file2.writerow(["id", "value1"])
for lines in file:
if "id" in lines:
ids = re.findall(r'(\d+)', lines)
if "value1" in lines:
value1 = re.findall(r'2[\w\.:-]+', lines)
file2.writerow([ids, value1])
getting output-
id value1
['0'] ['234w-76-54']
['1'] ['2354w44-7-54']
Desired output-
id value1
0 234w-76-54
1 2354w44-7-54

file2.writerow([ids[0], value1[0]])?re.searchinstead ofre.findall