Hi everyone! I am trying to debug someones code and I have found the problem. The program loops through an array of strings and count's certain ends. The problem is that some of these strings end with _
, so the counting goes wrong. I would like to use regex, but I am not experienced enough. Could someone help me?
I would like to loop through the array and per string check if it ends with _
('s) and trim all of these _
off to put them again in the array!
Update
Thanks for the rstrip
suggestion! I have tried to write a code that works with my data, but no luck yet...
data_trimmed = []
for x in data:
x.rstrip('_')
data_trimmed.append(x)
print(data_trimmed)
But this still returns: ['Anna__67_______', 'Dyogo_3__', 'Kiki_P1_', 'BEN_40001__', .... ]