python中使用列表推導式,簡便實現兩個list中相同元素的去重,也就是去除一個list中和另一個list中相同的元素。
list1 = ['a','b','c','d']
list2 = ['a','b,'e']
list1_not_in_list2 = [i for i in list1 if i not in list2]
list2_not_in_lis1 = [i for i in list2 if i not in list1]
python中使用列表推導式,簡便實現兩個list中相同元素的去重,也就是去除一個list中和另一個list中相同的元素。
list1 = ['a','b','c','d']
list2 = ['a','b,'e']
list1_not_in_list2 = [i for i in list1 if i not in list2]
list2_not_in_lis1 = [i for i in list2 if i not in list1]
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。