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 &quot...
Windom asked 9/8, 2011 at 19:11

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 ...
Mesoderm asked 8/6, 2016 at 4:37

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...
Algorithm asked 19/8, 2010 at 14:56

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*...
Mantle asked 8/4, 2014 at 18:54

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...
Englishry asked 28/8, 2014 at 15:13

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...
Hack asked 14/3, 2012 at 0:14

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 ...
Trichoid asked 24/5, 2013 at 8:4

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...
Nichols asked 10/1, 2009 at 22:12

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), ...
Heinie asked 10/2, 2013 at 20:13

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...
Colostomy asked 2/7, 2014 at 19:40

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: ...
Psyche asked 22/7, 2010 at 11:3

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...
Toole asked 4/9, 2014 at 16:52

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', ...
Unhesitating asked 17/8, 2018 at 14:37

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...
Hightest asked 9/6, 2016 at 16:57

© 2022 - 2024 — McMap. All rights reserved.