The*_*gri 1 python python-3.x python-3.7
I am trying to make it so that every even thing in a list goes to one variable, and every odd one goes to another. For example, let's say x = ["a", "b", "c", "d"]. How would I make y = ["a", "c"] and z = ["b", "d"]?
I have not made any script with this yet, but I will in the future
你的意思是:
>>> y, z = x[::2], x[1::2]
>>> y
['a', 'c']
>>> z
['b', 'd']
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |