Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
program help
#1
Find out duplicate number between 1 to N numbers. (anyone have a code)
Reply
#2
You could try to add them to a set(), if a number fails, it is a duplicate.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
2 basic ways :
list1 = [1,2,3,4,5,6,1,2,3]
set1 = set(list1)
print(list(set1))
or
list2 = [1,3,5,7,9,1,3]
list3 = []
for i in list2:
    if i not in list3:
        list3.append(i)
print(list3)
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#4
Unfortunately, you've been given solutions by now, but in future please try to come up with a solution before asking for help (pen and paper are great tools!). You need to develop problem solving skills as a programmer.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020