tuples Questions
1
Solved
I just started learning C++17 fold expressions. I understand that it is possible to apply a fold expression to a tuple, like in the following example (inspired by replies to this question):
#includ...
Kanchenjunga asked 10/7, 2020 at 20:8
3
Solved
I am not sure I quite understand what's happening in the below mini snippet (on Py v3.6.7). It would be great if someone can explain to me as to how can we mutate the list successfully even t...
Stealing asked 27/6, 2020 at 18:38
1
Solved
I want to do the following in Rust:
let (command, options) = message.splitn(2, ' ');
This can't be done because of:
expected struct `std::str::SplitN`, found tuple
The split will always...
3
Solved
I'm just starting out in Scala. I find myself using tuple variables a lot.
For example, here's some code I wrote:
/* Count each letter of a string and return in a list sorted by character
* coun...
3
Solved
In python I can do this:
def f((a, b)):
return a + b
d = (1, 2)
f(d)
Here the passed in tuple is being decomposed while its being passed to f.
Right now in scala I am doing this:
def f(ab: (...
7
Solved
Given a string that is a sequence of several values separated by a commma:
mStr = 'A,B,C,D,E'
How do I convert the string to a list?
mList = ['A', 'B', 'C', 'D', 'E']
5
Solved
In Julia vec reshapes multidimensional arrays into one-dimension arrays.
However it doesn't work for arrays of arrays or arrays of tuples.
A part from using array comprehension, is there another wa...
3
Solved
Is there any one liner method to convert datetime to simple tuple
>>> from datetime import datetime, timedelta
>>> new_date = datetime. today() + timedelta(12)
>>> new_d...
Isocline asked 14/5, 2020 at 8:12
10
Solved
I am translating a program from C# to Java. In the C# code, the developer uses Tuple. I need to translate this C# code into Java code. Therefore, does Java have an equivalent variable type to C#'s ...
6
Solved
I have a list called pairs.
pairs = [("a", 1), ("b", 2), ("c", 3)]
And I can access elements as:
for x in pairs:
print x
which gives output like:
('a', 1) ('b', 2) ('c', 3)
But I want to ...
6
Solved
I am presented with a list made entirely of tuples, such as:
lst = [("hello", "Blue"), ("hi", "Red"), ("hey", "Blue"), ("yo", "Green")]
How can I split lst into as many lists as there are ...
7
Solved
My question is in the code:
template<typename... Ts>
struct TupleOfVectors {
std::tuple<std::vector<Ts>...> tuple;
void do_something_to_each_vec() {
//Question: I want to do ...
1
Solved
I was recently surprised to find that the "splat" (unary *) operator always captures slices as a list during item unpacking, even when the sequence being unpacked has another type:
>&g...
Micelle asked 24/4, 2020 at 0:35
1
Solved
If I have a list/array of tuples like this: [(15, 36, 39), (9, 40, 41)]
How do I sort these by the first element? By the last element? By their sum?
1
I have a LINQ query that uses tuples for optimization. However, I'm unable to find working syntax to unpack the tuple in the arguments, which seems surprising because C# does support unpacking tupl...
3
Solved
I was looking at the documentation and found an example code that looked unfamiliar.
std::cmp::Reverse - Rust
use std::cmp::Reverse;
let mut v = vec![1, 2, 3, 4, 5, 6];
v.sort_by_key(|&num| ...
4
Solved
I have an object which needs to be "tagged" with 0-3 strings (out of a set of 20-some possibilities); these values are all unique and order doesn't matter. The only operation that needs to be done ...
Causal asked 7/7, 2019 at 4:44
5
Solved
After seeing a conversation in a forum from many years ago that was never resolved, it caused me to wonder how one would correctly create a tuple that referenced itself. Technically, this is a very...
Pishogue asked 8/8, 2012 at 21:27
2
Solved
I have a class that is expected to take std::tuple of certain types (arbitrary count is allowed) as a template argument. I want to declare a tuple of vectors of the types. For instance, I have
tem...
3
Solved
Say I have a namedtuple like this:
FooTuple = namedtuple("FooTuple", "item1, item2")
And I want the following function to be used for hashing:
foo_hash(self):
return hash(self.item1) * (self.i...
Thedrick asked 11/7, 2010 at 13:37
3
Solved
I understand that Swift's tuples serve, for example, as a simple way for a function to return multiple values. However, beyond this "simplicity aspect", I don't see very well any necessity of using...
3
Solved
It is well known that tuples are not defined by parentheses, but commas. Quote from documentation:
A tuple consists of a number of values separated by commas
Therefore:
myVar1 = 'a', 'b...
Azral asked 12/1, 2018 at 5:47
2
Solved
I want processing large numbers with 10k+ digits, so I use tuples, because integer type cannot be used (precision of number is important, because sum of digits). There are only 2 unique digits, 9 a...
Goosefish asked 1/4, 2020 at 6:10
9
Solved
I have a Swift program that does interop with a C library. This C library returns a structure with a char[] array inside, like this:
struct record
{
char name[8];
};
The definition is correctly...
3
If I have a recursive function that builds up a tuple, where in each function it creates a new tuple by appending/prepending an element to the tuple, is it better to grow it towards the front or to...
© 2022 - 2024 — McMap. All rights reserved.