如何通过将元素1连接到元素2等将lst1转换为lst2?
lst1=[' ff 55 00 90 00 92 00 ad 00 c6 00 b7 00 8d 00 98 00 87 00 8a 00 98 00 8f 00 ca 01 78 03 54 05 bf']
到
lst2=[ff55, 0090, 0092, 00ad, 00c6, 00b7, 008d, 0098, 0087, 008a, 0098, 008f, 00ca, 0178, 0354,05bf]
我试过了,但并不像预期的那样:
for i in lst:
lstNew = []
tempList = i.split()
lenList = len(tempList)
#print tempList
index = 0
while (index < lenList):
print tempList[index] + tempList[index+1]
index = index + 2
这样可以吗:
或者
假设您有一个由空格分隔的两个字母组成的字符串,则可以执行以下操作:
这利用了我最喜欢的库funcy
更新:
正如评论中所建议的;这里有一个稍微好一点的版本:
你的清单格式是
让我们替换所有空格并将其转换为字符串
现在我们可以每4个字符递增一次得到结果
相关问题 更多 >
编程相关推荐