[英]Remove Special Character from tuple of list
我想从元组中删除特殊字符。 考虑一个例子
(['\x0cSome Namel\n'],['\x0c4739 2332 3450 1111\n'])
我想让 output 成为
([Some Name ],[4739 2332 2450 1111])
我尝试使用split
和replace
,即使在使用它返回相同的 output 之后也是如此
假设您在输入中有以下字符串:
string = r"""['\x0cSome Namel\n'] ['\x0c4739 2332 3450 1111\n']"""
在这种情况下,您可以使用replace
function:
string = string.replace(r"'\x0c", "").replace(r"\n'", "")
Output:
[Some Namel] [4739 2332 3450 1111]
如果您特别想删除问题中显示的两个字符,并且每个字符串中的 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:
(['Some Namel'], ['4739 2332 3450 1111'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.