小编Muk*_*hra的帖子

在不影响数值的情况下反转字符串列表

我有一个字符串列表.

arr = ['17 -> 16 -> 1 -> 8 -> 0', '5 -> 2 -> 3 -> 6 -> 0']
Run Code Online (Sandbox Code Playgroud)

我想要反转字符串,我正在使用此代码:

x = arr[::-1]
x = x.replace(">-", "->")
x = x[5:]
Run Code Online (Sandbox Code Playgroud)

但输出是:

arr = ['0 -> 8 -> 1 -> 61 -> 71', '0 -> 6 -> 3 -> 2 -> 5']
Run Code Online (Sandbox Code Playgroud)

然而,我需要输出为:

arr = ['0 -> 8 -> 1 -> 16 -> 17', '0 -> 6 -> 3 -> 2 -> 5']
Run Code Online (Sandbox Code Playgroud)

python

-1
推荐指数
1
解决办法
79
查看次数

标签 统计

python ×1