看板 [ Python ]
討論串[問題] 動態產生FOR迴圈的辦法
共 9 篇文章
首頁
上一頁
1
2
下一頁
尾頁

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者mikapauli (cablin)時間14年前 (2011/12/24 00:30), 編輯資訊
0
0
0
內容預覽:
在這個例子忽然想到,我一直以來以為python的內建函式都是純函式,也就是沒有副作用. ,但next似乎就是一個反例,為什麼不用.next() method就好? 想問一下Python標準庫. 中還有沒有這類的函式? 另外有什麼方法可以讓iterator直接reset嗎?. --. 「死ぬのっていや

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者mikapauli (cablin)時間14年前 (2011/12/18 03:03), 編輯資訊
0
0
0
內容預覽:
我的寫法:. def product(lists):. indices = range(len(lists)). iters = [iter(l) for l in lists]. values = [next(i) for i in iters]. while True:. yield value
(還有382個字)

推噓2(2推 0噓 0→)留言2則,0人參與, 最新作者mathfeel (mathfeel)時間14年前 (2011/12/14 06:21), 編輯資訊
0
0
0
內容預覽:
處理任意多個list的方法:. #!/usr/bin/env python. def list_product(*args):. if not args:. yield "". else:. for ii in args[0]:. for jj in list_product(*args[1:]):
(還有355個字)

推噓1(1推 0噓 5→)留言6則,0人參與, 最新作者curist (SERIOUSLY!!!???)時間14年前 (2011/12/12 20:27), 編輯資訊
0
0
1
內容預覽:
沒用itertools的話. def add_up(i, *lists):. return ''.join([list[i] for list in lists]). [add_up(i, listOne, listTwo, listThree) for i in range(len(listOne
(還有157個字)

推噓2(2推 0噓 3→)留言5則,0人參與, 最新作者suzuke (suzuke)時間14年前 (2011/12/12 19:04), 編輯資訊
0
0
1
內容預覽:
import itertools. listOne = ['a','b','c']. listTwo = ['d','e','f']. listThree = ['g','h','i']. for x in itertools.product(listOne,listTwo,listThree):.
首頁
上一頁
1
2
下一頁
尾頁