-1

I want to remove special characters from tuple. Consider an example

(['\x0cSome Namel\n'],['\x0c4739 2332 3450 1111\n'])

I want to get output to be

([Some Name ],[4739 2332 2450 1111])

I tried using split and replace even after using that it is returning same output

Lexpj
  • 921
  • 2
  • 6
  • 15
Iamgroot
  • 112
  • 7
  • 1
    How do they get there in the first place? They are utf-8-sig. So there is a chance you can make the import and remove them on the import. Here is some info about utf-8-sig: [link](https://stackoverflow.com/questions/57152985/what-is-the-difference-between-utf-8-and-utf-8-sig) – enslaved_programmer Dec 26 '22 at 09:49

2 Answers2

0

Consider you have following string on input:

string = r"""['\x0cSome Namel\n'] ['\x0c4739 2332 3450 1111\n']"""

In this case you can use replace function:

string = string.replace(r"'\x0c", "").replace(r"\n'", "")

Output:

[Some Namel] [4739 2332 3450 1111]
Alderven
  • 7,569
  • 5
  • 26
  • 38
0

If you specifically want to remove the two characters shown in the question and if their position in each string is irrelevant then:

mytuple = ['\x0cSome Namel\n'], ['\x0c4739 2332 3450 1111\n']

for te in mytuple:
    for i, s in enumerate(te):
        te[i] = s.replace('\n', '').replace('\f', '')

print(mytuple)

Output:

(['Some Namel'], ['4739 2332 3450 1111'])
DarkKnight
  • 19,739
  • 3
  • 6
  • 22