[英]multiply columns in the list using core python, without any import libraries
[英]Iterate the start of a list without any import in Python
x = []
for i in l[0::3]:
x.append(i)
for j in l[1::3]:
x.append(j)
for k in l[2::3]:
x.append(k)
print(x)
我想隨機抽取一個清單
[1, 2, 3, 4, 5, 6, 7]
那會回來
[1, 4, 7, 2, 5, 4, 7]
但要列出任何數字。 有沒有辦法將啟動次數增加1?
使用列表理解:
>>> xs = [1, 2, 3, 4, 5, 6, 7]
>>> [x for i in range(3) for x in xs[i::3]]
[1, 4, 7, 2, 5, 3, 6]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.