[英]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.