python - Python3 表达式增量的替代方案
问题描述
想象一下,我有index = 0
,hash = '06123gfhtg75677687fgfg4'
并且我想处理表达式,如hash[i++]
。如何在 Python3 中做到这一点?
注意,我需要index = 1
在这个表达式之后。如果可能的话,我需要一行表达式。
预期用途如下:
enc = bytes(enc % len(session_key))
x = bytes(data[i] ^ session_key[enc++]) + ej)
data[i] = ej = x
解决方案
您可以使用itertools.count()
object, withnext
来给出当前值并增加它。这将++
正确模拟后缀 C/C++ 运算符。
例子:
import itertools
c = itertools.count() # starts at 0, but can be passed a start value as argument
s = 'abc'
print(s[next(c)])
print(s[next(c)])
print(s[next(c)])
按顺序打印 a,b,c。
推荐阅读
- java - 过滤列表后点击 ListView Item
- jquery - 即使填写了必填字段,Jquery Validate 插件也会引发错误
- laravel - Laravel、Vuejs、axios 获取登录用户的帖子
- android - 改造预期为 BEGIN_OBJECT,但为 STRING
- ios - 是否可以制作包含 SwiftUI 的 Swift 项目模板?
- android - 如何将数据从 Android 中的数据报套接字发送到 Node js 服务器?
- php - 如何在 Laravel 中从 json 索引计数
- node.js - 在 Vagrant 框中连接 Angular 到 Node/express
- python - 单链表 Python 头部和尾部
- java - 首选项屏幕中的自定义列表首选项对话框布局,带有自定义列表项