tuples

Python, Convert 9 tuple UTC date to MySQL datetime format

I am parsing RSS feeds with the format as specified here: http://www.feedparser.org/docs/date-parsing.html date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0) I am a bit stumped at how to get this into the MySQL datetime format (Y-m-d H:M:S)? ...

How do I implicitly convert Tuples to vector in Scala

I want to be able to implicitly convert Tuples of numbers (Ints and double) into a vector object. Assuming a Vector class with a + method case class Vector(x: Double, y:Double){ def + (v:Vector)= new Vector(x+v.x,y+v.y) } My goal is to have the following code work. val vec = (1,2)+(.5,.3) // vec == Vector(1.5,2.3) I can get it...

What does the term "Tuple" Mean in Relational Databases?

Please explain what is meant by tuples in sql?Thanks.. ...

Multiple Tuple to Two-Pair Tuple in Python?

What is the nicest way of splitting this: tuple = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') into this: tuples = [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')] Assuming that the input always has an even number of values. ...

Why is the use of tuples in C++ not more common?

Why does nobody seem to use tuples in C++, either the Boost Tuple Library or the standard library for TR1? I have read a lot of C++ code, and very rarely do I see the use of tuples, but I often see lots of places where tuples would solve many problems (usually returning multiple values from functions). Tuples allow you to do all kinds o...

Semantics of F# let statement with comma

I'm learning F#. I started by looking over the F# samples from Microsoft. I ran across this statement: let line1,line2 = use sr = System.IO.File.OpenText @"test.txt" let line1 = sr.ReadLine() let line2 = sr.ReadLine() (line1,line2) Can anyone explain this statement to me? What type is being defined here? A functio...

Get a unique list/tuple element given a condition in python

Hi! How do I get a tuple/list element given a condition in python? This occurs pretty often and I am looking for a nice-few-lines-pythonic way of doing this. here could be an example: Consider a tuple containing 2D points coordinates like this: points = [[x1, y1],[x2, y2],[x3, y3], ...] And I would like to get the point that minimi...

Pythonic way to split comma separated numbers into pairs

I'd like to split a comma separated value into pairs: >>> s = '0,1,2,3,4,5,6,7,8,9' >>> pairs = # something pythonic >>> pairs [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)] What would # something pythonic look like? How would you detect and handle a string with an odd set of numbers? ...

Sorting a tuple that contains lists

I have a similar question to this one but instead my tuple contains lists, as follows: mytuple = ( ["tomato", 3], ["say", 2], ["say", 5], ["I", 4], ["you", 1], ["tomato", 6], ) What's the most efficient way of sorting this? ...

Tuples( or arrays ) as Dictionary keys in C#

I am trying to make a Dictionary lookup table in C#. I need to resolve a 3-tuple of values to one string. I tried using arrays as keys, but that did not work, and I don't know what else to do. At this point I am considering making a Dictionary of Dictionaries of Dictionaries, but that would probably not be very pretty to look at, thou...

Difference between Vector, Set, and Tuple

As the title says, what is the differences between vectors, sets, and tuples in programming? ...

Efficient Tuple List Comparisons

I am kind of hitting a wall on this problem and I was wondering if some fresh brains could help me out. I have a large list of four element tuples in the format: (ID number, Type, Start Index, End Index) Previously in the code, I have searched through thousands of blocks of text for two specific types of substrings. These tuples stor...

How do I convert a nested tuple of tuples and lists to lists of lists in Python?

I have a tuple containing lists and more tuples. I need to convert it to nested lists with the same structure. For example, I want to convert (1,2,[3,(4,5)]) to [1,2,[3,[4,5]]]. How do I do this (in Python)? ...

Why are positional queries bad?

I'm reading CJ Date's SQL and Relational Theory: How to Write Accurate SQL Code, and he makes the case that positional queries are bad for example, this INSERT: INSERT INTO t VALUES (1, 2, 3) Instead, you should use attribute-based queries like this: INSERT INTO t (one, two, three) VALUES (1, 2, 3) Now, I understand that the first...

Adding tuples to produce a tuple with a subtotal per 'column'

What is the most pythonic way of adding the values of two or more tuples to produce a total for each 'column'? Eg: >>> a = (10, 20) >>> b = (40, 50) >>> c = (1, 3) >>> ??? (51, 73) I've so far considered the following: def sumtuples(*tuples): return (sum(v1 for v1,_ in tuples), sum(v2 for _,v2 in tuples)) >>> print sumtuples(a,...

Managing collections of tuples in Objective-C

I am fairly new to Objective-C and was wondering what the best way to manage collections of tuples was. In C I would use a 2D array or a struct. Should I be creating objects to contain these tuples? It seems like overkill for just sorting lists or is there no real extra load generated by object initialisation? ...

Iterative find/replace from a list of tuples in Python

I have a list of tuples, each containing a find/replace value that I would like to apply to a string. What would be the most efficient way to do so? I will be applying this iteratively, so performance is my biggest concern. More concretely, what would the innards of processThis() look like? x = 'find1, find2, find3' y = [('find1', 'rep...

Find unique elements in tuples in a python list

Is there a better way to do this in python, or rather: Is this a good way to do it? x = ('a', 'b', 'c') y = ('d', 'e', 'f') z = ('g', 'e', 'i') l = [x, y, z] s = set([e for (_, e, _) in l]) I looks somewhat ugly but does what i need without writing a complex "get_unique_elements_from_tuple_list" function... ;) edit: expected value ...

Iterate over pairs in a list (circular fashion) in Python

The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first). I've thought about two unpythonic ways of doing it: def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] and: def pairs(lst): return zip(lst,lst[1:]+[lst[0]])...

Parse error of nested tuples in scala

When writing the following code in scala var m = Map((0,1) -> "a") m += ((0,2), "b") // compilation error I'm getting the error type mismatch; found : Int(0) required: (Int, Int) However the changing the syntax of the tuple from (X,Y) to (X -> Y) works var m = Map((0,1) -> 'a) m += ((0,2) -> 'b) // compiles file Even though...