values = ['random word1', 20, 'random word2', 54…]
该列表有一个字符串,然后是一个值,然后又是一个字符串,然后是一个值。后面跟着值的字符串数量是随机的。单词是随机的,值也是随机的
我想将列表转换为这样的内容:
values = [['random word1', 20], ['random word2', 54]…]
最佳答案
values = ['random word1', 20, 'random word2', 54]
values = [values[i:i+2] for i in range(0,len(values),2)]
print(values)
关于python - 在 Python 中创建列表内的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74167340/