How to remove a character from the first element of each tuple in a list of tuples in Python

1 Answer

0 votes
tplList = [("py_thon", 4), ("ja_va", 1), ("c_", 10)]
char = "_"

tplList = [(tpl[0].replace(char, ''), tpl[1]) for tpl in tplList]

print(tplList)



'''
run:

[('python', 4), ('java', 1), ('c', 10)]

'''

 



answered Dec 4, 2022 by avibootz
edited Dec 4, 2022 by avibootz
...