- 2
print the duplicates in the list
we have to print the duplicates in the list . if there is no duplicates then print null
11 ответов
+ 6
K.CHINNI KRISHNA ,
this a nice challenge!
if you really have a problem, we need some more details from you:
▪︎give a clear and complete description about your task
▪︎if your question is related to an exercise in a tutorial, please mention the tutorial name and the lesson number
▪︎if there are error messages please post them here
▪︎give at least one sample with input data and the expected output
▪︎to be able to find out the issues you have, we need to see your code
=> please put your code in playground, save it there and post a link to it here.
thanks for your understanding!
+ 3
l = [1,1,2,2,3,3,4,5,6,5,5,5,5]
duplicates = []
for i in l:
if l.count(i) > 1:
duplicates.append(i)
if len(duplicates) != 0:
print(set(duplicates))
else:
print(None)
+ 2
l = [7, 3, 2, 3, 6 ,7, 5, 6]
duplicates = []
for i in l:
if l.count(i) == 2:
duplicates.append(i)
if len(duplicates) != 0:
print(set(duplicates))
else:
print(None)
# Output: {3, 6, 7}
+ 1
Obloev Komronbek ,
you are showing a really nice code to help someone solving a task. we all appreciate this very much!
(this is my personal statement - but it is not to criticize someone !!)
but there is an issue by giving a ready solution, when the op has not done and shown his attempt first.
as a part of the community i believe that learning by doing is more helpful, than just using a shared solution. we should act more as a mentor.
it is a very successful way when we are giving hints and help, so that the op is able to solve his task by himself. it would be great if you are going to help us to keep sololearn what it is:
▪︎a unique place to learn (we are a "self" learning platform!)
▪︎an absolutely great community that is willing to help other people
▪︎a great resource of people which has an unbelievable knowledge in coding and a long lasting experience
▪︎a place to meet people and to discuss with them all the possible points of view
thanks for your understanding
+ 1
Lothar Yes you are right. It will not benefit anyone. I will try to explain next time. Thank you. I understand you
+ 1
Lothar
i tried as many time ..
this is my 1st question to join discuss ...
futher i will follow your instructions
+ 1
Delicate Cat
ok look into it....
happy coding!!!!!
+ 1
Obloev Komronbek
simple correct this statement...
if l.count(i)>1:
i get my code...
great , thank you!!!!!!
+ 1
Delicate Cat
l=[1,2,1,2,3,4,5,4,5,2,2,6,7,7]
l1=[]
for i in range (len(l)):
for j in range(len(l)):
if l[i]==l[j] and i != j:
l1.append(l[i])
print(set(l1))
0
Obloev Komronbek ,
i am sry to say that this code is extent to somehow for 2 duplicates
if u take 3 or more duplicates in a list is don't print ....
need some init
0
Delicate Cat
here the problem is count,there are many counts ,
i.e, one element repeted only once another is two times another is three as many as ..we can't tell that user may give as input...
the above mention program only detect that any value repeated twice then it goes to print then what about a value repeated thrice, four ..likewise