About 53 results
Open links in new tab
  1. python - How to create a "singleton" tuple with only one element ...

    Jul 12, 2024 · Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single …

  2. Create tuple of multiple items n Times in Python

    Nov 12, 2016 · Do note that the final result is a tuple containing four references to the same tuple (id(a[0]) == id(a[1]) evaluates to True). Tuples are immutable, so it doesn't matter, but if you …

  3. How to create tuple with a loop in python - Stack Overflow

    Feb 17, 2018 · So, if you really need to change a tuple during run time: Convert the tuple into a list; Make the necessary changes to the list; Convert the list back to a tuple; or. Create a list; …

  4. python - Use list comprehension to build a tuple - Stack Overflow

    Mar 14, 2013 · tup = tuple((element.foo, element.bar) for element in alist) Technically, it's a generator expression. It's like a list comprehension, but it's evaluated lazily and won't need to …

  5. python - create a tuple from columns in a pandas DataFrame

    It does create a tuple in the correct format but when fed to stats.f_oneway() it returns f and p values of the same length as each row of the tuple. This is the case if I were to pass a tuple …

  6. dictionary - python swapped tuple to dict - Stack Overflow

    Dec 3, 2024 · For the tuple, t = ((1, 'a'),(2, 'b')) dict(t) returns {1: 'a', 2: 'b'} Is there a good way to get {'a': 1, 'b': 2} (keys and vals swapped)?

  7. python - Converting string to tuple without splitting characters ...

    To add some notes on the print statement. When you try to create a single-element tuple as part of a print statement in Python 2.7 (as in print (a,)) you need to use the parenthesized form, …

  8. Create a tuple from an input in Python - Stack Overflow

    The input is a string, and passing that to tuple() will create a tuple from the string's characters. So for example, for the OP's input of 1,1 , your code will output ('1', ',', '1') – Tomerikoo

  9. How to create a tuple of tuples in python? - Stack Overflow

    Nov 13, 2012 · I want to combine: A = (1,3,5) B = (2,4,6) into: C = ((1,2), (3,4), (5,6)) Is there a function that does this in python?

  10. types - What are "named tuples" in Python? - Stack Overflow

    Jun 4, 2010 · In Python inside there is a good use of container called a named tuple, it can be used to create a definition of class and has all the features of the original tuple. Using named …

Refresh