我有一个变量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/