FAQ: Learn Python - Practice Makes Perfect - Remove_duplicates

faq

#1

This community-built FAQ covers the “Remove_duplicates” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Remove_duplicates_:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!


#2

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

#3

Alternate solution:-
vowels = [3,2,1,3,4,5,7]

vowels.sort()

print vowels

emp=[]

for i in vowels:
if i not in emp:
emp.append(i)

print emp


#4

That works perfect, but “vowels” is a really bad variable name, why did you use it? :slight_smile:


#5

I was practicing some using some other problems and rewrote my existing code to fit this .Yah variable name does not make sense. I agree.


#7

Hey, I was wondering why this would not work for Remove_duplicates. Every time I press run, it loads for forever before determining that it didn’t work. I don’t need a piece of working code, I just want to know why this one doesn’t work.

def remove_duplicates(list_here):
dupe_removed_list = [ ]
for element1 in dupe_removed_list:
for element in list_here:
if element != element1:
dupe_removed_list.append(element)
return dupe_removed_list

I can’t seem to find any error codes that can help me find why this wouldn’t work if that helps.


#8

There is no element in this list…

for element1 in dupe_removed_list:

so an empty list is returned.


#9

@mtf Thanks for the explanation Roy! One more question - would this code work if I put in a temporary element (like “test”) and removed said element before returning dupe_removed_list?


#10

That would be fudging. Better to not iterate that list in the outer loop. Try iterating in the inner loop when we know that element will point to a real value.


#11

Thanks for all the help @mtf


#12

def remove_duplicats(list):
res =
for i in list:
if i == i:
list.remove(i)
return list

print remove_duplicats([1,1,2,2])

it return the same result so why it’s wrong ???!!
you are making it difficult guys


#13

Won’t that always be True?


#14

I tried to write my code like this,
can you please please explain why it gives me error?
I don’t get the solution of the exercise “remove_duplicates” so I would like to find another easier solution…

def remove_duplicates(numbers):
numbers.sort()
emp =
for n in numbers:
if n[0] != n[1]:
emp.append(n)
print remove_duplicates([1, 1, 2, 3])


#15

Sorting changes the order, which may not be such a good thing. n is an element value. Are we sure it is an iterable? We could go through the lines, but I think we need those questions answered first.