python - 在 Python 中使用字符串作为代码进行解码
问题描述
我想要做的是有一个程序来压缩像 AAABBBBCAAAaaDD -> A3B4CA3a2D2 这样的字符串,然后解压缩它。第一个函数已经可以工作,但第二个函数似乎无法看到字符串的第一个元素:
taba = list(string)
decompressed = ''
for i in range(2, len(taba)):
k = 0
if str(taba[i]).isnumeric():
while k < int(taba[i]):
decompressed += taba[i-1]
k += 1
输入 = AAABBBBCAAAaaDD,字符串 = A3B4CA3a2D2,解压后的字符串返回 BBBBCAAAaaDD。什么会导致循环不包含 taba[2-1]?
解决方案
Pretty sure it's because you're indexing from 2 instead of 0? What was the reasoning behind that? What were you trying to accomplish?
推荐阅读
- python - 使用微软翻译服务将英文翻译成中文
- java - Eclipse java SE 8 - 缺少 javaSE 1.8 执行环境
- shell - Oozie Shell 操作输出数据超出其限制 [2048]
- javascript - mongo 和 node.js 中的点后的多个命令
- javascript - 全屏自定义视频播放器,但是当我展开全屏时,控件不会出现
- bin - 如何在 Windows 上连接两个二进制文件
- python-3.x - 以字节模式编写文件并在 Python 中放置行分隔符
- php - 在 Woocommerce 我的帐户地址和帐户详细信息中设置唯一的验证错误通知
- reactjs - 流式中继的createFragmentContainer
- azure - VM 上的 Azure 网站:如何仅允许访问印度的 IP 地址