I have the following list:
labels = [fixed acidity', 'volatile acidity', 'citric acid]
I want to replace the empty spaces between the words of the list items with "_"
Code1 is working, the first output of Code2 looks fine, but the second does not.
Code1:
labels[0] = labels[0].replace(' ', '_')
labels[1] = labels[1].replace(' ', '_')
labels[2] = labels[2].replace(' ', '_')
Code2:
for label in labels:
label = label.replace(' ','_')
print(label)
print(labels)
Output of print(label): fixed_acidity volatile_acidity citric_acid
the output of print(labels): ['fixed acidity', 'volatile acidity', 'citric acid']
Any idea what went wrong?