[英]Remove Special Character from tuple of list
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我想让 output 成为
([Some Name ],[4739 2332 2450 1111])
I tried using split
and replace
even after using that it is returning same output我尝试使用split
和replace
,即使在使用它返回相同的 output 之后也是如此
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:在这种情况下,您可以使用replace
function:
string = string.replace(r"'\x0c", "").replace(r"\n'", "")
Output: Output:
[Some Namel] [4739 2332 3450 1111]
If you specifically want to remove the two characters shown in the question and if their position in each string is irrelevant then:如果您特别想删除问题中显示的两个字符,并且每个字符串中的 position 无关紧要,则:
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: Output:
(['Some Namel'], ['4739 2332 3450 1111'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.