The instructions for the program itself said that the order for which the list items are returned is itself not important, they even mentioned an example for this in which what they want is for duplicated items to be removed, that is it, it does not say that the order is important hence why the program I wrote is relevant.
You are right! Yes, according to instructions you don't have to care about order preservation. In my opinion it's a stupidity, I already explained why I think so.
I really don't try to offend you. In fact, I appreciate that you are helping others. I just believe that we should try to maintain higher standard of explanations than codecademy. In your first post here you have said Use your powers wisely and create awesome things!. Exactly! Every method has some pros and cons and if you want to create a discussion that aggregates different functions - you should present their positive and negative aspects.
This is my opinion. You don't have to agree with me. Really.
The point from my original post was to demonstrate that there are multiple solutions for this particular problem.You wanted to make the issue at hand more detailed and you are most definitely right when you say that order is important, then again it might not be important depending on the task at hand, for this particular task it is not.
And here I see my mistake. I think that codecademy is not a good learning resource and I thought that you want to aggregate functions to remove duplicates from the list, not list solutions to this particular exercises. The difference is big, right?
You want to conclude on my code not being Pythonic, according to you it is not idiomatic to what Python stands for? If anything It is a matter of you not liking the solution for your stated reasons which in itself are not entirely valid based on the task given by codeacademy.
Python is similar to Ruby in this matter. I think there are three levels of code quality in Python:
- Poorly written code.
- Well written code.
- Pythonic code.
Your code in my opinion is poorly written, it reminds me of this code:
if n % 2 == 1:
result = True
result = False
Is this code pythonic? Nope. It's a poorly written snippet.
The code provided by @zeziba is not a different solution. It's a well-written version of your function.
Now regarding time complexity, you mentioned that a beginner might have an issue with understanding the convertion between sets and lists and vice versa, but you want me to go into why would one method of solving the problem will be more efficient than the other? don't get me wrong, algorithm efficiency is definitely a subject that must not be passed, but lets go by levels man, first let them understand that they have choices, then we teach them why a particular choice is more efficient than the other in terms of algorithm efficiency.
No, I mentioned that beginner might not be aware of the fact that your method destroys the order of elements.
You have said that they should use the laziest approach. They should not. They should be aware of pros and cons of each method to chose one best suited for the given task (also in the future, not only in this single exercise).
TThere is a great, simple way to show time complexity of all methods - time benchmark. 4 random data sets. In the first set
500 short lists, in the second set
500 longer lists, etc. The essence of time complexity, don't you think?
I like how you do know what you are talking about. I apologize for calling you ignorant on the matter.
No need to apologize We are two random guys. You can call me whatever you want, and I really mean this. I am here to share some thoughts about programming, not to argue about with you about my humble person.
As a parting note, care to share some examples as to what other solutions might they have for this particular problem set? And I am saying that in the nicest non hostile way.
Just to clarify - I don't think that you are mean.
Sure, I would love to!
My favourite solution is:
seen = set()
return [x for x in l if x not in seen and not seen.add(x)]
This is the fastest order preserving solution that I know. I think this function was written by Dave Kirby, but, unfortunately, I am not sure. I will try to find a source later.
If I would not care about order I would probably use this function: