Nonsteroidal anti-inflammatory drugs (NSAIDs) may protect against skin cancer, according to a study published online December 18 in the Journal of Investigative Dermatology. NSAID use has been ... 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.

Understanding the Context

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... 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.

Key Insights

... When reading, list is a reference to the original list, and list[:] shallow-copies the list. 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)".

Final Thoughts

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. 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?