How do I find the duplicates in a list and create another list with them?

前端 未结 30 2247
梦谈多话
梦谈多话 2020-11-22 00:56

How can I find the duplicates in a Python list and create another list of the duplicates? The list only contains integers.

30条回答
  •  滥情空心
    2020-11-22 01:26

    use of list.count() method in the list to find out the duplicate elements of a given list

    arr=[]
    dup =[]
    for i in range(int(input("Enter range of list: "))):
        arr.append(int(input("Enter Element in a list: ")))
    for i in arr:
        if arr.count(i)>1 and i not in dup:
            dup.append(i)
    print(dup)
    

提交回复
热议问题