Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如我有一个列表 x
x = ['(A)','(B)','(C)']
如果我们 reversed() 它,它将看起来像这样。
x = ['(C)','(B)','(A)']
现在,我想将括号()更改为哈希#。
我正在寻找的输出
x = ['#C#','#B#','#A#']
我可以在python中做到这一点吗?
尝试这个:
import re x = ['(A)','(B)','(C)'] x = [re.sub(r"\((\w)\)", r"#\1#", item) for item in reversed(x)] print(x) >>>['#C#', '#B#', '#A#']