Python_Note_11–set 用法

今天写几个小程序练练手: list1 = [‘a’, ‘b’, ‘apple’, ‘are’, ‘b’, ‘cannot’, ‘a’, ‘b’] list2 = [99, 10, 2, 45, 3, 55, 98, 99, 100, 2000, 4] 1.scan list 中某个元素a出现的次数: def scan1(li): return len([elem for elem in li if elem == ‘a’]) scan1(list) — result is: 2 2.scan list 中长度不为1的元素: def scan2(li): return [elem for elem in li … Read morePython_Note_11–set 用法