The first, [:], is creating a slice (normally often used for getting just part of a list), which happens to contain the entire list, and thus is effectively a copy of the list. The second, list(), is using the actual list type constructor to create a new list which has contents equal to the first list. I have a piece of code here that is supposed to return the least common element in a list of elements, ordered by commonality: def getSingle(arr): from collections import Counter c = Counte...

Understanding the Context

Is there a way in Python to list all installed packages and their versions? I know I can go inside python/Lib/site-packages and see what files and directories exist, but I find this very awkward. ... When reading, list is a reference to the original list, and list[:] shallow-copies the list.

Key Insights

When assigning, list (re)binds the name and list[:] slice-assigns, replacing what was previously in the list. Also, don't use list as a name since it shadows the built-in. The notation List<?> means "a list of something (but I'm not saying what)". Since the code in test works for any kind of object in the list, this works as a formal method parameter. Using a type parameter (like in your point 3), requires that the type parameter be declared.

Final Thoughts

The Java syntax for that is to put <T> in front of the function. This is exactly analogous to declaring formal parameter ... By using a : colon in the list index, you are asking for a slice, which is always another list. In Python you can assign values to both an individual item in a list, and to a slice of the list. What is the difference between list [1] and list [1:] in Python? You cannot put lists in sets since lists are mutable and could change (which could affect whether they are duplicate to another list in the set).

I would suggest a different approach for a list of lists, e.g. as covered in this question about removing duplicates from a list of lists.