python - 如何将 a2c3d 转换为 accfd?
问题描述
在这里,我们只需要将写入前一个字符 ascii 值的 num 添加。
我试过了
if __name__ == '__main__':
n = input()
list1 = list(n)
for i in list1:
if list1[i] is not chr:
list1[i] = list1[i-1] + list1[i]
print(list(n))
解决方案
这种方法的优点是不使用列表。它将前一个字符存储在prev
变量中以在数字的情况下使用。
text = 'a2c3d'
result = ''
prev = None
for ch in text:
if ch.isdigit() and prev:
result += chr(int(ch) + ord(prev))
else:
result += ch
prev = ch
print(result)
推荐阅读
- javascript - 如何在 chart.js 中更改 X 轴间隔
- hadoop - java.io.IOException:来自 Hadoop 数据节点上 inputStream 的过早 EOF
- ios - 非公共 API 使用
- python - 如何在python中使用tensorflow模型
- module - Kentico,全球事件未触发
- excel - 如何在谷歌脚本(marco excel)中查找数组中存在的元素数量
- python - Python追加到列表覆盖列表中的所有其他元素
- linear-programming - 线性规划线去除最优解
- javascript - 允许小数点后两位数
- image - Javafx GridPane ColumnConstraints 导致在需要重叠的地方进行裁剪