Remove specific characters from a list

Asked

Viewed 64 times

0

My question is this, is there any way to remove the comma from a list? I’m using the . strip to remove the brackets, but when setting the comma as parameter does not work, I tried . replace but ended up giving error.

    with open('reservas.txt', 'w') as doc:
        for k in range(0, len(reserva)):
             doc.write(f'{str(save_temp[k])} {str(save_temp2[k]).strip("][")}\n'

Output in txt file ends up being

17423215562 0, 2

I need the comma removed. Thanks in advance.

1 answer

1

Hello, there are ways to remove characters from lists, however it is not your case since this created a string when using the function write(string) for write in the document. So why not just use f'{str(save_temp[k])} {str(save_temp2[k]).strip("][")}\n'.replace(',','')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.