tuple

c++/boost: use tuple ctors when subclassing

Hi there, is there some way to use a boost tuple's ctors as an addition to the subclass methods (and ctors) like here? // typedef boost::tuple<int, SomeId, SomeStatus> Conn; // Conn(1); // works and initializes using default ctors of Some* struct Conn : boost::tuple<int, AsynchId, AccDevRetStatus> {}; Conn(1); // "no matching function ...

Matching of tuples

From what I understood I can use pattern-matching in a match ... with expression with tuples of values, so something like match b with ("<", val) -> if v < val then true else false | ("<=", val) -> if v <= val then true else false should be correct but it gives me a syntax error as if the parenthesis couldn't be used: File "oc...

How can I iterate over only the first variable of a tuple

In python, when you have a list of tuples, you can iterate over them. For example when you have 3d points then: for x,y,z in points: pass # do something with x y or z What if you only want to use the first variable, or the first and the third. Is there any skipping symbol in python? ...

Haskell Convert List to List of Tuples

Hello, i have a list like this ["peter","1000","michell","2000","kelly","3000"] and i would like to convert to [("peter",1000),("michell", 2000),("kelly",3000)] Please help. Thanks. ...

Haskell List of Tuple Search

Hello to all, i have a list of tuple like this [("username", 123), ("df", 54), ("as",2 34)] I need to search the value based on username. I have using lookup but i need to change the value of the integer and write back to file. My logic of this is to delete the tuple and insert another new tuple value rather than change it. Any idea...

Erlang - Write a pattern that will bind a variable to the second element in this tuple {<0.206.0>, {rect, 10, 30}}

How do I write a pattern that will bind a variable to the second element in this tuple {<0.206.0>, {rect, 10, 30}}? I.e. "thing in place of pattern here" that results in Shape having the value {rect, 10, 30}. Pattern = {<0.206.0>, {rect, 10, 30}} It's the <0.206.0> part that is confusing me. ...

Concatenate tuples in empty dict

errors = {} #errorexample errors['id'] += ('error1',) errors['id'] += ('error2',) #works but ugly errors['id'] = ('error1',) errors['id'] += ('error2',) If 'error1' is not present it will fail. Do I really have to extend dict? ...

Why Tuple's items are ReadOnly?

I was thinking to use Tuple class to store 2 integer information (StartAddress, EndAddress) I need in my program. But I discover that Tuple items are ReadOnly, so if I need to set a value for an item, I need to re-instantiate a Tuple. What is the reason behind this design decision? ...

How to sort a list of inter-linked tuples?

lst = [(u'course', u'session'), (u'instructor', u'session'), (u'session', u'trainee'), (u'person', u'trainee'), (u'person', u'instructor'), (u'course', u'instructor')] I've above list of tuple, I need to sort it with following logic.... each tuple's 2nd element is dependent on 1st element, e.g. (course, session) -> session is dependent...

How can I explode a tuple so that it can be passed as a parameter list?

Let's say I have a method definition like this: def myMethod(a, b, c, d, e) Then, I have a variable and a tuple like this: myVariable = 1 myTuple = (2, 3, 4, 5) Is there a way I can pass explode the tuple so that I can pass its members as parameters? Something like this (although I know this won't work as the entire tuple is consid...

How meny items cn contain tuple or list in python?

How many items can contain tuple or list in python? What will be if it is 10 000? ...

C++0x : are tuples of tuples allowed?

I'm currently working on a class with a lot of templates and being able to build tuples of tuples would make it a lot easier But I tried this simple code in MSVC++ 2010: #include <tuple> void main() { auto x = std::make_tuple(std::make_tuple(5, true)); } And I get a compilation error. The same problem happens if I don't use std...

How do I get integers from a tuple in Python?

I have a tuple with two numbers in it, I need to get both numbers. The first number is the x-coordinate, while the second is the y-coordinate. My pseudo code is my idea about how to go about it, however I'm not quite sure how to make it work. pseudo code: tuple = (46, 153) string = str(tuple) ss = string.search() int1 = first_int(ss) ...

Python - convert list of tuples to string

Which is the most pythonic way to convert a list of tuples to string? I have: [(1,2), (3,4)] and I want: "(1,2), (3,4)" My solution to this has been: l=[(1,2),(3,4)] s="" for t in l: s += "(%s,%s)," % t s = s[:-1] Is there a more pythonic way to do this? ...

C++0x: iterating through a tuple with a function

Hi, I have a function named _push which can handle different parameters, including tuples, and is supposed to return the number of pushed elements. For example, _push(5) should push '5' on the stack (the stack of lua) and return 1 (because one value was pushed), while _push(std::make_tuple(5, "hello")) should push '5' and 'hello' and r...

Python: Unpacking an inner nested tuple/list while still getting its index number

I am familiar with using enumerate(): >>> seq_flat = ('A', 'B', 'C') >>> for num, entry in enumerate(seq_flat): print num, entry 0 A 1 B 2 C I want to be able to do the same for a nested list: >>> seq_nested = (('A', 'Apple'), ('B', 'Boat'), ('C', 'Cat')) I can unpack it with: >>> for letter, word in seq_nested: pr...

howto extract simple string from tuple in python (newbie question)

I have a rather large tuple which contains: [('and', 44023), ('cx', 37711), ('is', 36777) .... ] I just want to extract the first string delimited by the single quotes, so the output for the above tuple would be: and cx is How do I code this (with extensibilty built in to some degree)? ...

Function returning a tuple or None: how to call that function nicely?

Hello, Suppose the following: def MyFunc(a): if a < 0: return None return (a+1, a+2, a+3) v1, v2, v3 = MyFunc() # Bad ofcourse, if the result was None What is the best way to define a function that returns a tuple and yet can be nicely called. Currently, I could do this: r = MyFunc() if r: v1, v2, v3 = r else: # bad!! ...

Returning a tuple of multipe objects in python C api

I am writing a native function that will return multiple python objects PyObject *V = PyList_New(0); PyObject *E = PyList_New(0); PyObject *F = PyList_New(0); return Py_BuildValue("ooo", V, E, F); This compiles fine, however, when I call it from python, I get an error\ SystemError: bad format char passed to Py_BuildValue How can t...

How can I call a function that takes 2 parameters with a Tuple2?

I have a function like so: def print(name:String, surname:String) { println(name + " " + surname) } I also have a Tuple2: val johnsmith = ("John", "Smith") When I call print with johnsmith I get the following error: scala> print(johnsmith) error: not enough arguments for meth...