Questions tagged [tuples]
In programming, tuples are simple *product types*, representing ordered collections of types.
tuples
12,074
questions
0
votes
1
answer
55
views
How can I have each `using` of a base struct be a different type?
I have a tuple of elements that I want to access using std::get with the type name:
template<typename... Params>
struct SomeType
{
std::tuple<Params...> params;
};
using TypeOne = ...
-4
votes
1
answer
50
views
How to convert a tuple which includes a [string] to a dictionary item
I have this list:
address_table3 = [(1, ['21 South Main']), (2, ['1560 West St']), (3, ['1900 Broadway'])]
I want to convert it to a dictionary with the address as key and integer as value.
When I ...
-1
votes
2
answers
56
views
Why do I not get the more helpful "sum() can't sum strings, use join" message, but "unsupported operand types for +"?
I'm learning Python now.
I created a function
def my_func(my_tuple):
return sum(my_tuple)
Then I do
print(my_func(("a", "b")))
And I get:
TypeError: unsupported operand type(...
1
vote
1
answer
95
views
Any way to name tuple items?
A tuple can we written as the following:
auto tp = std::tuple<int, bool>();
I have a lot of them and they each have a comment above them naming what each element represents, E.g.
//age, ...
1
vote
3
answers
88
views
`type <nameOfType> = Typeclass` compiles, but `type <nameOfType> = (Typeclass, Typeclass)` doesn't
I've been reading about the renaming of pre-existing types using the haskell's type and, as much as I could understand, the type is only used for renaming concrete types, like Int, Integer, Char, ...
1
vote
2
answers
64
views
A list of tuples from dictionary where values are lists
I need to convert a dictionary in a form {1: ['a', 'b', 'c', 'd'], 2: ['e', 'f', 'g', 'h']} to a list of tuples in a form [(1, 'a', 'b', 'c', 'd'), (2, 'e', 'f', 'g', 'h')].
When I try that:
...
1
vote
1
answer
39
views
How do You Convert a List of Strings into a Frozenset and Add it to a Set of Frozensets?
I have a variable with n words, separated by whitespaces. str.split() returns a list of these words, which is then converted to a tuple with tuple(), which is finally converted to a frozenset and ...
2
votes
1
answer
34
views
What’s the meaning of `T extends readonly unknown[] | []` in TypeScript’s function signature of `Promise.all`?
I noticed an interesting (possibly hacking) part in TypeScript’s lib.d.ts:
interface PromiseConstructor {
/* ... */
/**
* Creates a Promise that is resolved with an array of results when all ...
2
votes
0
answers
57
views
Can't use tuples with a 0 as the second variable in a tuple-enum in Python [closed]
I want to use an enum as a tuple for my Board-coordinates in my chess program like this:
from enum import Enum
class Pos(tuple, Enum):
A1 = (0, 0)
A2 = (0, 1)
B1 = (1, ...
0
votes
0
answers
78
views
Casting a tuple<int *, int, int, int*> to tuple<void*, int, int, void*> is causing an ASAN stack use out of scope issue [duplicate]
I have a code that is creating an ASAN stack use out of scope issue. Calling f() below will cause it.
#include <iostream>
#include <tuple>
using TupleData = std::tuple<void *, int, int,...
0
votes
0
answers
20
views
Printing list and tuple elements combined with unpacking operator [duplicate]
I have a following code with different outputs
def func1(*args):
print(type(args))
print('Func1')
for k in args:
print (k)
def func2(args):
print(type(args))
print('Func2')...
1
vote
1
answer
37
views
Tuple matching using SQLAlchemy
Let's say I have a db of Customers. I want to fetch data and filter rows by exact pairs.
I want to do the following using sqlalchemy:
SELECT first_name, age
FROM Customers
WHERE (first_name, age) in ((...
1
vote
1
answer
55
views
Why is [1 | 2] not a subtype of [1 | []] | [2 | []] in TypeScript?
In TypeScript, I have an API whose input is a union of tuples and I have a value whose type is a tuple of unions that I want to pass into it. It seems like this works in most cases, but I can't figure ...
0
votes
1
answer
66
views
What is the meaning of the new operator when creating a modern tuple? Or is it a rudiment?
Let's say the new operator is left for the modern tuple as a rudiment. That is, it can be ignored.I can write it when returning a value from a method or property. But I can't write it when declaring a ...
0
votes
3
answers
95
views
Convert a complex string representation of a list (containing tuples, which look like function calls) into a list
I am trying to create a fixture for unit testing. I retrieve data from an API and need data that looks like what I get from the API without making the call to the API. I need to create a number of ...