我有一个这样的列表:
list=[' is ', ' the ', ' . ', ' .kda ', ...]
我想知道如何改变它,如下所示:
1-放在|每个之后'
2-删除'除第一个和最后一个之外的所有内容
3-删除所有,
4-从列表的乞讨和结尾移除[和]
5-改变所有.,\.即使它并不孤单。例如更改u.s为u\.s
输出:
list= is | the | \. | \.kda | ...
字符串操作
answer = str(list).replace("'", "'|").replace(".", "\.").strip('[').strip(']')
list=[' is ', ' the ', ' . ', ' .kda ']
# add a r before the string declaration to specify it as a regex string
re_list = r"|".join(list).replace('.', '\.')
print(re_list)
#>>>' is | the | \. | \.kda | ...'