tuples Questions
1
Solved
I've got a function with a generic that is a tuple of 1 or a tuple of 2 elements.
I want to ensure that all properties used in the function use the same length tuple.
type TypeA = [string] // Tuple...
Undershorts asked 25/1, 2023 at 12:16
11
Solved
Is there a way in Python to serialize a dictionary that is using a tuple as key?
e.g.
a = {(1, 2): 'a'}
simply using json.dumps(a) raises this error:
Traceback (most recent call last):
File "...
8
Solved
I was wondering what would be a Pythonic way of sorting a list of tuples by two keys whereby sorting with one (and only one) key would be in a reverse order and sorting with the the other would be ...
7
Solved
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)?
Ultimately, I want to be able to return 1 given 'a' or...
Checkrein asked 24/9, 2010 at 1:4
6
Solved
I have the following tuple of tuples:
my_choices=(
('1','first choice'),
('2','second choice'),
('3','third choice')
)
and I want to add another tuple to the start of it
another_choice = ('0...
3
Solved
I got a error saying:
unsupported operand type(s) for -: 'int' and 'tuple'
How do I correct it?
from scipy import integrate
cpbar = lambda T: (3.826 - (3.979e-3)*T + 24.558e-6*T**2 - 22.733e-9*T*...
6
Solved
I'm going to need your help with this constant tuple error I keep getting. Seems that it is a common mathematical error that many have. I have read almost every instance of TypeError including 'not...
Taima asked 26/10, 2013 at 17:57
3
Solved
I am writing a C function that takes a Python tuple of ints as an argument.
static PyObject* lcs(PyObject* self, PyObject *args) {
int *data;
if (!PyArg_ParseTuple(args, "(iii)", &d...
5
Solved
So in C++ there is now make_from_tuple as:
T obj = std::make_from_tuple<T>( { Args... args } ); // args represents a tuple
but how would one do:
T* obj = std::make_new_from_tuple<T*>( ...
Exarchate asked 15/12, 2022 at 9:3
6
Solved
I want to convert a color tuple to a color name, like 'yellow' or 'blue'
>>> im = Image.open("test.jpg")
>>> n, color = max(im.getcolors(im.size[0]*im.size[1]))
>>> prin...
10
Solved
I have some object.ID-s which I try to store in the user session as tuple. When I add first one it works but tuple looks like (u'2',) but when I try to add new one using mytuple = mytuple + new.id ...
12
Solved
Say I have a Python function that returns multiple values in a tuple:
def func():
return 1, 2
Is there a nice way to ignore one of the results rather than just assigning to a temporary variable...
4
Solved
I have a tuple of characters like such:
('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
How do I convert it to a string so that it is like:
'abcdgxre'
Bertrambertrand asked 28/10, 2013 at 17:45
4
Solved
I want to find the minimum of a list of tuples sorting by a given column. I have some data arranged as a list of 2-tuples for example.
data = [ (1, 7.57), (2, 2.1), (3, 1.2), (4, 2.1), (5, 0.01), ...
6
Solved
I'm trying to create an array of tuples in Swift, but having great difficulty:
var fun: (num1: Int, num2: Int)[] = (num1: Int, num2: Int)[]()
The above causes a compiler error.
Why's that wrong...
8
Solved
I'm trying to obtain the n-th elements from a list of tuples.
I have something like:
elements = [(1,1,1),(2,3,7),(3,5,10)]
I wish to extract only the second elements of each tuple into a list:
...
7
Solved
I have IEnumerable<string> which looks like {"First", "1", "Second", "2", ... }.
I need to iterate through the list and create IEnumerable<Tuple<string, string>> where Tuples wil...
Antilog asked 8/3, 2011 at 23:29
2
Solved
In Python, if I run the code:
T=('A','B','C','D')
D={}
i=0
for item in T:
D[i]=item
i=i+1
Can I be sure that D will be organized as:
D = {0:'A', 1:'B', 2:'C', 3:'D'}
I know that tuples' ord...
2
Solved
In C++23, the ranges (sub)library has gained std::ranges::zip, which zips multiple ranges into a single range of std::tuple's (or pairs). This is nice, and precludes requiring implementing this our...
Karakalpak asked 23/11, 2022 at 21:43
2
Solved
I have a tuple:
details = ({}, [])
As there is no data in the following tuple I want to return a null response. For this I am writing:
if not details:
return Response({})
else:
print "Not n...
Uniform asked 7/2, 2018 at 10:3
5
Solved
Two integers in Python have the same id:
a = 10
b = 10
a is b
>>> True
If I take two lists:
a = [1, 2, 3]
b = [1, 2, 3]
a is b
>>> False
according to this link Senderle answered...
Lenticel asked 4/7, 2016 at 17:21
2
Solved
Tuple in python is immutable by design, so if we try to mutate a tuple object, python emits following TypeError which make sense.
>>> a = (1, 2, 3)
>>> a[0] = 12
Traceback (most r...
Twigg asked 11/11, 2022 at 16:3
3
I have the following pandas dataframe df:
Description Code
0 Apples 014
1 Oranges 015
2 Bananas 017
3 Grapes 021
I need to convert it to a tuple of tuples, like this:
my_fruits = ( ('Apples', ...
4
Solved
I'd like to write an extension for tuples of (e.g.) two value in Swift. For instance, I'd like to write this swap method:
let t = (1, "one")
let s = t.swap
such that s would be of type (String, ...
Cupboard asked 4/2, 2015 at 9:18
2
Solved
I'm trying to do something like this in python:
def f():
b = ['c', 8]
return 1, 2, b*, 3
Where I want f to return the tuple (1, 2, 'c', 8, 3). I found a way to do this using itertools followed...
© 2022 - 2024 — McMap. All rights reserved.