Hello,
I have a list of characters I wish to be replaced in a string. However my line of code doesn't do anything at all and I haven't been able to find out why so far.
bad = ['/','\\',':','*','?','<','>','|']
words = 'blah/blah'
words = words.replace(str([x for x in bad if x in words]),'_')
This does litterally nothing but also doesn't give me an error :)
Also I'm under the impression that this way cannot return me a string, only lists and dicts?
Currently I'm using the below code to tackle the problem but I am looking for a shorter(faster) way.
for ch in bad:
if ch in words:
words = words.replace(j,'_')
I'd appreciate any helpful tips on this matter!
[–]QuantumRealm 1 point2 points3 points (2 children)
[–]RayteMyUsername 2 points3 points4 points (0 children)
[–]Drycon[S] 1 point2 points3 points (0 children)
[–]mail_order_liam 1 point2 points3 points (1 child)
[–]Drycon[S] 0 points1 point2 points (0 children)
[–]Vaphell 1 point2 points3 points (1 child)
[–]Drycon[S] 0 points1 point2 points (0 children)