File size: 925 Bytes
ca165c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import csv
def process_csv(input_file, output_file):
with open(input_file, 'r') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row
output_data = []
for row in reader:
word, score = row[0], int(row[1])
if score == 1:
# Break down the word into letters and append each letter with ,1
for letter in word:
output_data.append([letter, '1'])
else:
output_data.append([word, str(score)])
with open(output_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Letter', 'Score'])
writer.writerows(output_data)
if __name__ == "__main__":
input_csv = "word_scores.csv"
output_csv = "word_scores2.csv"
process_csv(input_csv, output_csv)
print(f"Conversion complete. Output saved to {output_csv}")
|