推 froce: countDict = list(item for item in l1 if l1.count(item)12/12 20:34
→ s4028600: 原來如此 利用出現過幾次來做條件嗎...12/12 22:25
→ CaptPlanet: [l1.remove(x) for x in l1]12/12 23:20
→ CaptPlanet: ans = set(l2) - set(l1)12/12 23:20
這個邏輯有點難懂
但是行不通
只會打印一個
推 cuteSquirrel: 用字典或list.count(), 透過出現次數去篩選12/13 00:42
count是搞懂了
字典還是很難理解
推 eric781101: iterate一遍丟進set, set.remove(e) if e in set else12/13 15:27
→ eric781101: set.add(e)12/13 15:27
看不懂
試不出來
推 Sunal: set() ^ set()12/13 20:26
可以用
但是^是什麼函數
看不懂邏輯
是減法嗎
推 gene50814: a = pd.Series(l1)12/14 05:13
→ gene50814: b = list(a[a.duplicated])12/14 05:13
→ gene50814: [i for i in l1 if i not in b]12/14 05:13
→ gene50814: 更正 duplicated()12/14 05:14
推 Sunal: set 做 XOR 就好了 一行結束 就是我上一個推文推的12/14 10:01
推 Sunal: pandas用在這太大材小用了12/14 10:03
※ 編輯: s4028600 (39.12.62.158 臺灣), 12/15/2019 18:30:03
※ 編輯: s4028600 (39.12.62.158 臺灣), 12/15/2019 18:35:37
推 omd: 列表不合併,直接轉set,然後照Sunal大方法 12/15 18:36
※ 編輯: s4028600 (125.230.140.168 臺灣), 12/15/2019 19:12:37
→ ddavid: set XOR不符原Po需求,因為合併後重複包括a裡面直接就出現 12/15 22:47
→ ddavid: 兩次以上的這種,set XOR只會刪掉兩邊都出現的 12/15 22:47
→ crazycy: 都轉成Set了 裡面怎麼會有重複的... 12/15 23:30
推 pingxx123: from collections import Counter 12/16 13:11
→ pingxx123: l2 = Counter(l1) 12/16 13:11
→ pingxx123: result = [key for key,value in c.items() if value = 12/16 13:11
→ pingxx123: = 1] 12/16 13:11
→ pingxx123: 最後一行是這個才對 12/16 13:12
→ pingxx123: result = [key for key,value in l2.items() if value 12/16 13:12
→ pingxx123: == 1] 12/16 13:12
推 ddavid: @crazycy 你仔細看一下原題 12/16 23:54
→ crazycy: 抱歉 沒注意到 12/17 08:58
→ carrlyea: l2 = [x for x in l1 if l1.count(x)==1] 12/17 11:32
推 TuCH: 樓上要改成 l2 = [x for x in set(l1) if l1.count(x)==1] 12/17 12:05