本帖最后由 ooxx7788 于 2017-4-28 10:52 编辑 def duplicate_count_num(nums):
if isinstance(nums, str):
return [(nums.count(c), c) for c in set(nums) if nums.count(c) > 1] # (次数,数字)
elif isinstance(nums, list):
return list(filter(lambda x: x[0] != 1, zip(map(nums.count, set(nums)), set(nums)))) # (次数,数字)
duplicate_count_num([1,2,3,4,5,1,1,1,2])
[(4, 1), (2, 2)]
str1 = '12312245532432543508932743284724532098349320320676965765'
duplicate_count_num(str1)
[(11, '2'), (3, '8'), (4, '0'), (10, '3'), (7, '5'), (4, '9'), (7, '4'), (4, '6'), (4, '7'), (2, '1')]
|