Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

program to print duplicates from a list of integers in python

lst = [ 3, 6, 9, 12, 3, 30, 15, 9, 45, 36, 12, 12]
dupItems = []
uniqItems = {}
for x in lst:
   if x not in uniqItems:
      uniqItems[x] = 1
   else:
      if uniqItems[x] == 1:
         dupItems.append(x)
      uniqItems[x] += 1
print(dupItems)
Comment

Python | Program to print duplicates from a list of integers

# program to print duplicate numbers in a given list
# provided input
list = [1, 2, 1, 2, 3, 4, 5, 1, 1, 2, 5, 6, 7, 8, 9, 9]
 
new = []  # defining output list
 
# condition for reviewing every
# element of given input list
for a in list:
 
     # checking the occurrence of elements
    n = list.count(a)
 
    # if the occurrence is more than
    # one we add it to the output list
    if n > 1:
 
        if new.count(a) == 0:  # condition to check
 
            new.append(a)
 
print(new)
 
Comment

PREVIOUS NEXT
Code Example
Python :: python c api 
Python :: Python | Set 3 (Strings, Lists, Tuples, Iterations) 
Python :: how to open cmd as administrator with python 
Python :: metros para cm para mm 
Python :: how to print tic tac toe border on terminal in python 
Python :: flask docker redirect container name 
Python :: get database image in dajngo 
Python :: Creating column based on existing column 
Python :: how to install pygame for python 3.8.5 
Python :: using ipfn in python 
Python :: data structures in python 
Python :: three periods in python 
Python :: python two list into dictinaray 
Python :: Python Program to Display Powers of 2 Using Anonymous Function 
Python :: beautifulsoup documentation 
Python :: frequency domain parameter of speech 
Python :: arabic text recognition from pdf using python 
Python :: transfer sound to hz with python 
Python :: python selenium disable JavaScript Detection 
Python :: when was barracoon written 
Python :: pandan jaya lrt 
Python :: plot a against b 
Python :: how to analyze data from dataframe in python 
Python :: Reading from a file way03 
Python :: py random sample 
Python :: raspberry pi pwm controlled leds 
Python :: send2trash 
Python :: Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained. python 
Python :: Python RegEx Escape – re.escape() Syntax 
Python :: rest api save file python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =