tuples

Triples in Java [duplicate]

扶醉桌前 提交于 2019-12-05 17:00:22
This question already has an answer here: Using Pairs or 2-tuples in Java [duplicate] 14 answers Possible Duplicate: Does Java need tuples? Does Java support triples or at least pairs? Does Java support tuples? I am trying to find a way to make a list so that it has a triple with initial point as first, terminal point at last, and distance in the middle. However, I can't seem to find anything about it. I usually just create my own class for these purposes. class Pair<A,B> { A a; B b; public Pair( A a, B b ) { this.a = a; this.b = b; } } If you have three related values like that it implies me

How to convert a tuple to a string in Python?

早过忘川 提交于 2019-12-05 16:43:14
After a MySQL select statement, I am left with the following: set([('1@a.com',), ('2@b.net',), ('3@c.com',), ('4@d.com',), ('5@e.com',), ('6@f.net',), ('7@h.net',), ('8@g.com',)]) What I would like to have is a emaillist = "\n".join(queryresult) to in the end, have a string: 1@a.com 2@b.net 3@c.com etc What would be the proper way to convert this nested tuple into string? As long as you're sure you have just one element per tuple: '\n'.join(elem[0] for elem in queryresult) A list comprehension along the lines of [item[0] for item in queryresult] should help. eg, emaillist = "\n".join([item[0]

python: class vs tuple huge memory overhead (?)

隐身守侯 提交于 2019-12-05 16:43:05
问题 I'm storing a lot of complex data in tuples/lists, but would prefer to use small wrapper classes to make the data structures easier to understand, e.g. class Person: def __init__(self, first, last): self.first = first self.last = last p = Person('foo', 'bar') print(p.last) ... would be preferable over p = ['foo', 'bar'] print(p[1]) ... however there seems to be a horrible memory overhead: l = [Person('foo', 'bar') for i in range(10000000)] # ipython now taks 1.7 GB RAM and del l l = [('foo',

pymssql: executemany value error - expected a simple type, a tuple or a list

谁说我不能喝 提交于 2019-12-05 14:01:53
grpidx_data=[] for i in range(0,len(data1)): grpidx_data.append((data1.loc[i,'price'],data1.loc[i,'id'])) cur.executemany("insert into grpidx values (%s,%s)",grpidx_data) I use python3.3 and pymssql. I want to import data from python to MSSQL. grpidx_data's type is list(tuple) ,like[(12,1),(34,2),...], I run the code above then got the error: ValueError: expected a simple type, a tuple or a list If I just use the data which type is list(tuple) , the code works fine. But when I use for loop got the data, even its type also list(tuple) ,its not working. So How to solve this problem? Thanks! I

Overloading + to support tuples

拟墨画扇 提交于 2019-12-05 10:15:09
I'd like to be able to write something like this in python: a = (1, 2) b = (3, 4) c = a + b # c would be (4, 6) d = 3 * b # d would be (9, 12) I realize that you can overload operators to work with custom classes, but is there a way to overload operators to work with pairs? Of course, such solutions as c = tuple([x+y for x, y in zip(a, b)]) do work, but, let aside performance, they aren't quite as pretty as overloading the + operator. One can of course define add and mul functions such as def add((x1, y1), (x2, y2)): return (x1 + x2, y1 + y2) def mul(a, (x, y)): return (a * x, a * y) but still

getting an element from a tuple [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-05 09:26:47
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why doesn't ADL find function templates? Calling get does not seem to invoke argument dependent lookup: auto t = std::make_tuple(false, false, true); bool a = get<0>(t); // error bool b = std::get<0>(t); // okay g++ 4.6.0 says: error: 'get' was not declared in this scope Visual Studio 2010 says: error C2065: 'get': undeclared identifier Why? 回答1: It's because you attempt to explicitly instantiate get function

Extracting Information from a Tuple (Python)

℡╲_俬逩灬. 提交于 2019-12-05 08:54:06
I'm currently using the httplib library in Python 2.7 to obtain some headers from a website to establish a) the filesize of a download and b) the last modified date of the file. I've used some online tools and these details do exist. I'm currently scripting my Python code and it appears to work correctly bringing back the required information. Nonetheless, the response containing the header information is a list containing a number of tuples. A sample of the response is below:- [('content-length', '2501479'), ('accept-ranges', 'bytes'), ('vary', 'Accept-Encoding'), ('server', 'off'), ('last

How to create named reference-type tuples?

ε祈祈猫儿з 提交于 2019-12-05 08:33:59
The following line creates a named ValueTuple : var tuple = (a:1, b:2, c:3, d:4, e:5, f:6); Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type? If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't. Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in TupleExtensions and back using the ToTuple overloads. If you don't really need the tuples, you can deconstruct

placing objects deriving from tuple into a vector in C++

≡放荡痞女 提交于 2019-12-05 08:28:42
I want to create a struct with 3 values: a string and two ints. The string is mandatory, but either (or both) of the ints are optional and can default to -1 if not specified. However, rather than use a struct, I thought I would try an std::tuple. In order to incorporate the optional-ness of the two ints, I setup a "Trio" class which inherits from std::tuple as below: #include <string> #include <tuple> class Trio : public std::tuple<std::string, int, int> { public: explicit Trio(std::string const & name, int val1 = -1, int val2 = -1) : tuple(name, val1, val2) { } }; Then I go to test the Trio

Use 4 (or N) collections to yield only one value at a time (1xN) (i.e. zipped for tuple4+)

孤街醉人 提交于 2019-12-05 08:09:43
scala> val a = List(1,2) a: List[Int] = List(1, 2) scala> val b = List(3,4) b: List[Int] = List(3, 4) scala> val c = List(5,6) c: List[Int] = List(5, 6) scala> val d = List(7,8) d: List[Int] = List(7, 8) scala> (a,b,c).zipped.toList res6: List[(Int, Int, Int)] = List((1,3,5), (2,4,6)) Now: scala> (a,b,c,d).zipped.toList <console>:12: error: value zipped is not a member of (List[Int], List[Int], List[Int], List[Int]) (a,b,c,d).zipped.toList ^ I've searched for this elsewhere, including this one and this one , but no conclusive answer. I want to do the following or similar: for((itemA,itemB