我试过序列生成器,比如Lambda,List comprehension等等,但是似乎我不能得到我真正想要的。我的最终目标是打印像string[1:3]
我要找的是:
a = [0,13,26,39]
b = [12,25,38,51]
str = 'If you are done with the file, move to the command area across from the file name in the RL screen and type'
read = str.split()
read[0:12]
['If', 'you', 'are', 'done', 'with', 'the', 'file,', 'move', 'to', 'the', 'command', 'area']
read[13:25]
['from', 'the', 'file', 'name', 'in', 'the', 'RL', 'screen', 'and', 'type']
你的意思是:
或者
使用
zip
:zip
返回元组列表,其中每个元组包含传递给它的iterables中相同索引上的项:如果您想要内存高效的解决方案,请使用
itertools.izip
,因为它返回一个迭代器。你知道吗如果要从切片列表创建字符串,可以使用
str.join
:更新:创建
a
和b
:相关问题 更多 >
编程相关推荐