About 129,000 results
Open links in new tab
  1. python - What's the difference between lists and tuples ... - Stack ...

    Dec 9, 2024 · So, if you want the first 3 values of a given list or tuple, the syntax would be the same: >>> my_list[0:3] [0,1,2] >>> my_tuple[0:3] [a,b,c] Comparing & Sorting - Two tuples or …

  2. python - Find an element in a list of tuples - Stack Overflow

    Specifically, dict(X) converts X into a dictionary where the last tuple of any common first element, is the value that is used. In the example of the OP, this would return (1,4) as opposed to both …

  3. Convert list to tuple in Python - Stack Overflow

    L is a list and we want to convert it to a tuple. L = [1, 2, 3] tuple(L) By invoking tuple, you convert the list (L) into a tuple. As done above. >> (1, 2, 3) you can go ahead and access any item in …

  4. python - List vs tuple, when to use each? - Stack Overflow

    For input parameters it's best to accept the most generic interface that does what you need. It is seldom just a tuple or list - more often it's sequence, sliceable or even iterable. Python's duck …

  5. python - How to sort a list/tuple of lists/tuples by the element at a ...

    Below example, we are sorting a list of tuple that holds the info abt time of certain event and actor name. We are sorting this list by time of event occurrence - which is the 0th element of a tuple. …

  6. python - How to convert list of tuples to multiple lists ... - Stack ...

    Suppose I have a list of tuples and I want to convert to multiple lists. For example, the list of tuples is [(1,2),(3,4),(5,6),] Is there any built-in function in Python that convert it to: [1,3,5],[2,4,6] This …

  7. python - How to merge lists into a list of tuples? - Stack Overflow

    Jul 10, 2016 · From my point of view, it seem's what I'm looking for and to work fine for the both (list and tuple). Because when you use print, you will see the right value (as expected and …

  8. python - Accessing a value in a tuple that is in a list - Stack Overflow

    Sep 10, 2018 · As mentioned, it is a list comprehension (covered in DiveIntoPython3, for example). Here are a few points: [x[1] for x in L] Notice the []'s around the line of code. These …

  9. python - How do I plot list of tuples? - Stack Overflow

    Use numpy to create the x-coordinate list and y-coordinate list. Working with large data sets is faster in numpy than using the iteration in Python suggested in other answers. Use pyplot to …

  10. python - Finding in elements in a tuple and filtering them - Stack …

    Jun 16, 2015 · new_list = [] for {item_var_or_vars} in {iterable}: if {boolean_expression}: new_list.append({expression}) The if {boolean_expression} bit is optional, just as it is in the for …

Refresh