看板 [ Python ]
討論串[問題]不用for迴圈尋找陣列中只出現過一次的資料
共 5 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓8(8推 0噓 25→)留言33則,0人參與, 最新作者sariel0322 (sariel)時間10年前 (2014/05/08 14:43), 編輯資訊
3
0
1
內容預覽:
我想要請問一下,如果我有一串數字. A = [9,5,5,4,7,6,4,1,2,0,10,9,7,....]. 要如何找出這列資料中只出現一次的數字,但不用到for迴圈的方法. 我只能想到說:. B = []. C = []. dataset = set(A). for i in dataset:
(還有63個字)

推噓3(3推 0噓 2→)留言5則,0人參與, 最新作者apua (Apua)時間10年前 (2014/05/11 23:48), 10年前編輯資訊
0
0
1
內容預覽:
收到! XDDD. # def f(L, N=set()): # it's bad. def f(L, N=None):. # print L,f.N. if N is None:. N = set(). if not L:. return []. elif L[0] in N:. return f
(還有363個字)

推噓2(2推 0噓 6→)留言8則,0人參與, 最新作者ccwang002 (亮)時間10年前 (2014/05/12 03:22), 10年前編輯資訊
0
0
6
內容預覽:
(冏冏,我看成有出現就好…… 明天再補了 > <). 完整檔案見 IPython Notebook. http://nbviewer.ipython.org/gist/ccwang002/bc1b047d0eca2c8f8bdd. 這真的要快的話,就不應該自己寫 for loop,所以我想得到最快的
(還有1811個字)

推噓1(1推 0噓 3→)留言4則,0人參與, 最新作者retard (Baby baby~~)時間10年前 (2014/05/12 04:57), 編輯資訊
0
0
1
內容預覽:
這應該是個 map reduce 的題目吧. l = [2, 3, 4, 5, 0, 1, 2, 3, 4, 2, 3, 5]. def func_map(a):. return [set([a]), set([a])]. def func_reduce(am, bm):. uaset, aset
(還有173個字)

推噓0(0推 0噓 8→)留言8則,0人參與, 最新作者yauhh (喲)時間10年前 (2014/05/21 01:50), 10年前編輯資訊
0
0
1
內容預覽:
def uniq(li):. A = li[:]. A.sort(). B = A[:-1]. return [x for x in A if (x, x) not in \. filter(lambda (x,y): x == y, zip(A[1:],B))]. --. 發信站: 批踢踢實業
首頁
上一頁
1
下一頁
尾頁