Dom*_*ger 0 python arrays python-3.x
我只是无法弄清楚如何在python中轻松实现它:
myArray = ["this ","is ","a ","test.","this ","is ","another ","test."]
Run Code Online (Sandbox Code Playgroud)
现在我想要输出
print(myArray[0:3]) -> "this is a test"print(myArray[4:7]) -> "this is another test"python中是否有一个功能允许在myArray中的for word中迭代整个数组...
我得到的是一个循环中的索引,它只告诉我应该"打印"它的哪个单词.
我更喜欢python"独家"变体,它简短而简单,最好的情况是一个内衬,它应该需要尽可能少的内存(快速甚至数千次尝试)
您可以尝试join(),我希望这是您正在寻找的解决方案
myArray = ["this ","is ","a ","test.","this ","is ","another ","test."]
print(' '.join(myArray[:4]))
print(' '.join(myArray[4:]))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |