About 278,000 results
Open links in new tab
  1. python - List vs tuple, when to use each? - Stack Overflow

    Using a tuple instead of a list is like having an implied assert statement that this data is constant, and that special thought (and a specific function) is required to override that. Some tuples can be used as …

  2. python - What's the difference between lists and tuples ... - Stack ...

    Mar 9, 2009 · In a list the values all have the same type and the length is not fixed. So the difference is very obvious. Finally there is the namedtuple in Python, which makes sense because a tuple is …

  3. Python typing: tuple[str] vs tuple[str, ...] - Stack Overflow

    Apr 25, 2022 · 22 giving a tuple type with ellipsis means that number of elements in this tuple is not known, but type is known:

  4. Are tuples more efficient than lists in Python? - Stack Overflow

    FWIW, list access is faster that tuple access in Python 2 but only because there is a special case for lists in BINARY_SUBSCR in Python/ceval.c. In Python 3, that optimization is gone, and tuples access …

  5. What is the difference between lists and tuples in Python?

    Jul 28, 2010 · A useful variant of tuple is its sub-type collections.namedtuple (requires Python 2.6 or better) which lets you access items by name (with attribute syntax) as well as by index (the normal …

  6. In Python, when to use a Dictionary, List or Set?

    Jul 1, 2019 · When you want to collect an immutable ordered list of elements, use a tuple. (For example, when you want a (name, phone_number) pair that you wish to use as an element in a set, you would …

  7. python - Static typing in python3: list vs List - Stack Overflow

    Oct 3, 2018 · 41 This question already has answers here: Using List/Tuple/etc. from typing vs directly referring type as list/tuple/etc (3 answers)

  8. python - what is difference betwen string and tuple? - Stack Overflow

    Mar 14, 2019 · Tuple they are immutable like strings and sequence like lists.They are used to store data just like list, just like string you cannot update or edit the tuple to change it you have to create a new …

  9. python - Using List/Tuple/etc. from typing vs directly referring type ...

    Sep 12, 2016 · What's the difference of using List, Tuple, etc. from typing module: from typing import Tuple def f (points: Tuple): return map (do_stuff, points) As opposed to referring to Python's types dire...

  10. Python Sets vs Lists - Stack Overflow

    May 14, 2010 · In Python 2, set is always the slowest. or is the fastest for 2 to 3 literals, and tuple and list are faster with 4 or more literals. I couldn't distinguish the speed of tuple vs list.