python - 在 Python 中编辑列表内容

标签 python string list edit

我有一个变量data:

data = [b'script', b'-compiler', b'123cds', b'-algo', b'timing']

我需要转换它以删除列表中所有出现的“b”。 我该怎么做?

最佳答案

不确定它是否有帮助 - 但它适用于您的示例:

initList = [b'script', b'-compiler', b'123cds', b'-algo', b'timing']
resultList = [str(x) for x in initList ]

或者在 P3 中:

resultList = [x.decode("utf-8") for x in initList ] # where utf-8 is encoding used

decode function. 上查看更多信息

您可能还想看看 the following related SO thread.

关于python - 在 Python 中编辑列表内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8077810/

相关文章:

javascript - 通过使用捕获的匹配项作为键将字符串替换为正则表达式

将一维字符串数组转换为c中的二维字符串数组

Python:我的 python 绘图反射(reflect)了 y = 0.5 线

Python 推特流时间线

python - Python如何执行没有.py扩展名的文件?

java - 字符串分词器分离

python - 如何使用 python 查找成对的卡包列表

list - 是否有一个函数可以展平嵌套的元素列表?

c# - 如何合并两个列表并删除重复项

python - 在Python中绘制单色bmp格式