Код: Выделить всё
{'\[\\n M a k i n g c o f f e e i s n o t r e l a t e d t o t h e c o n t e x t i n f o r m a t i o n p r o v i d e d .\]'}
Код: Выделить всё
Making coffee is not related to the context information provided.
Код: Выделить всё
import re
import json
import string
import re
my_int ={'\[\\n M a k i n g c o f f e e i s n o t r e l a t e d t o t h e c o n t e x t i n f o r m a t i o n p r o v i d e d .\]'}
a=\[\]
print(type(my_int))
result = re.sub(r'\[0-9\]', '\_', str(my_int))
print(type(result))
print(" ".join(result.split()))
print(result.translate({ord(c): None for c in string.whitespace}))
print(re.sub(r"\\s+", "", result), sep='')
print(re.sub(r"^\\s+", "", result), sep='')
print(re.sub(r"\\s+$", "", result), sep='')
print(re.sub(r"^\\s+|\\s+$", "", result), sep='')`
ПРИМЕЧАНИЕ. Здесь, как вы видите, все буквы являются отдельными символами, следовательно, я не могу удалить пробелы между ними.
Буду очень благодарен за помощь.
Подробнее здесь: https://stackoverflow.com/questions/759 ... -in-python