Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <code>list</code> keeps order, <code>dict</code> and <code>set</code> don't: when you care about order, therefore, you must use <code>list</code> (if your choice of containers is limited to these three, of course;-).</p> <p><code>dict</code> associates with each key a value, while <code>list</code> and <code>set</code> just contain values: very different use cases, obviously.</p> <p><code>set</code> requires items to be hashable, <code>list</code> doesn't: if you have non-hashable items, therefore, you cannot use <code>set</code> and must instead use <code>list</code>.</p> <p><code>set</code> forbids duplicates, <code>list</code> does not: also a crucial distinction. (A "multiset", which maps duplicates into a different count for items present more than once, can be found in <code>collections.Counter</code> -- you could build one as a <code>dict</code>, if for some weird reason you couldn't import <code>collections</code>, or, in pre-2.7 Python as a <code>collections.defaultdict(int)</code>, using the items as keys and the associated value as the count).</p> <p>Checking for membership of a value in a <code>set</code> (or <code>dict</code>, for keys) is blazingly fast (taking about a constant, short time), while in a list it takes time proportional to the list's length in the average and worst cases. So, if you have hashable items, don't care either way about order or duplicates, and want speedy membership checking, <code>set</code> is better than <code>list</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload