0

I am beginner in python, I was writing a code to remove all duplicate numbers from list.

first I tried using for loop but I got similar error

lis=[]
lis2=[]
n=print("enter number of items you want in the list \n")
i=0
while (i<n):
    a=input("enter element number ",i+1)
    lis.extend(a)
    i=i+1
for j in lis:
    if j not in lis2:
        lis2.extend(j)
print(" \n list after removing duplicates \n",lis2)
input()

Error: '<' not supported between instances of 'int' and 'NoneType'

Stoner
  • 846
  • 1
  • 10
  • 30
singlecell
  • 29
  • 1

2 Answers2

0

Try changing n=print("enter number of items you want in the list \n") to:

n_ = input("enter number of items you want in the list \n")
n = int(n_)

I've also noticed some errors after applying the above changes, which after some fixing becomes:

lis=[]
lis2=[]
n_=input("enter number of items you want in the list \n")
n = int(n_)
i=0
while (i<n):
    a=input("enter element number " + str(i+1))
    lis += [a]
    i=i+1
for j in lis:
    if j not in lis2:
        lis2 += [j]
print(" \n list after removing duplicates \n",lis2)
Stoner
  • 846
  • 1
  • 10
  • 30
0

Use append instead of extend (append is appending one item to a list while extend is adding a list to another list) more in here.

input receives one argument, more in here

lis=[]
lis2=[]
n=input("enter number of items you want in the list \n")
i=0
while (i<n):
    a=input("enter element number " + str(i + 1))
    lis.append(a)
    i=i+1
for j in lis:
    if j not in lis2:
        lis2.append(j)
print(" \n list after removing duplicates \n",lis2)
omri_saadon
  • 10,193
  • 7
  • 33
  • 58