The List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young

I swapped the order of the sub-questions to make this more useful for the most common case that most beginners are searching for.

Also, the question/top answer have 2 million views but very few upvotes.

The first way works for a list or a string;

The second way only works for a list, because slice assignment isn't allowed for strings.

The List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young 4

Other than that i think the only difference is speed:

It looks like it's a little.

I have a piece of code here that is supposed to return the least common element in a list of elements, ordered by commonality:

The List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young 7

From collections import counter c = counte

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 List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young 9

The second, list(), is using the actual.

The notation list means a list of something (but i'm not saying what).

The List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young 11

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.

The List Of Baseball All Time War Leaders Features Legendary Names Like Babe Ruth, Willie Mays, And Cy Young 13