tuple

Given a list and a bitmask, how do I return the values at the indices that are True?

I start with the following list s and bitmask b: s = ['baa', 'baa', 'black', 'sheep', 'have', 'you', 'any', 'wool'] b = [1, 0, 0, 0, 1, 1, 1, 0] # or any iterable with boolean values How do I write some function apply_bitmask(s, b) so that it returns ['baa', 'have', 'you', 'any'] ...

scala tuple unpacking

I know this question has come up many times in different ways. But it is still not clear to me. Is there a way to achieve the following. def foo(a:Int, b:Int) = {} foo(a,b) //right way to invoke foo foo(getParams) // is there a way to get this working without explicitly unpacking the tuple?? def getParams = { //Some calculations ...

Building an unordered map with tuples as keys

In a C++ program with Boost, I am trying to build an unordered map whose keys are tuples of doubles: typedef boost::tuples::tuple<double, double, double, double> Edge; typedef boost::unordered_map< Edge, int > EdgeMap; Initializing the map completes OK, however, when I try to populate it with keys and values EdgeMap map; Edge key (0...

Representing an immutable hierarchy using tuples

I am trying to represent a hierarchy using namedtuple. Essentially, every node has three attributes relevant to the hierarchy: parent, leftChild and rightChild (they also have some attributes that carry the actual information, but that is not important for the question). The problem is the circular reference between parents and children....

Python variable weirdness?

What's going on with my Python variable? old_pos seems to be linked to pos: Code: pos = [7, 7] direction = [1, 1] old_pos = pos print 'pos = '+str(pos) print 'old_pos = '+str(old_pos) pos[0] += direction[0] pos[1] += direction[1] print 'pos = '+str(pos) print 'old_pos = '+str(old_pos) Output: pos = [7, 7] old_pos = [7, 7...

Parsing indeterminate amount of data into a python tuple

I have a config file that contains a list of strings. I need to read these strings in order and store them in memory and I'm going to be iterating over them many times when certain events take place. Since once they're read from the file I don't need to add or modify the list, a tuple seems like the most appropriate data structure. Howe...

Why does adding a trailing comma after a string make it a tuple?

I want to know that why adding a trailing comma after a string makes it tuple. I.e. abc = 'mystring', print abc # ('mystring,) When I print abc it returns a tuple like ('mystring',). ...

Finding a Value within a Range in a List of Tuple Values in Python

I'm trying to get the Body Mass Index (BMI) classification for a BMI value that falls within a standard BMI range - for instance, if someone's BMI were 26.2, they'd be in the "Overweight" range. I made a list of tuples of the values (see below), although of course I'm open to any other data structure. This would be easy to do with SQL's...

linux "more" like code in python for very big tuple/file/db records/numpy.darray?

Dear All, I am in looking for a buffer code for process huge records in tuple / csv file / sqlite db records / numpy.darray, the buffer may just like linux command "more". The request came from processing huge data records(100000000 rows maybe), the records may look like this: 0.12313 0.231312 0.23123 0.152432 0.22569 0.311312 0.54549...

error: boost.fusion::for_each() and struct derived from boost.tuple

Hi all! on compilation this code: struct any_type: boost::tuple<std::string, std::string, std::string> { ... }; struct functor { void operator()(const std::string& v) { std::cout << v << std::endl; } }; int main() { any_type type; boost::fusion::for_each(type, functor()); } get error: no type named 'category' in...

template vector

Hi All, I'm trying to implement a function that allows me to make a call like this // veca is a vector of tuples in my case columnViewOfTuple<0>(veca); I implemented such function as follows template<int N> struct myfunction { template<typename T, typename R> std::vector<R> operator() (T& container) { std::vector<...

How to map a tuple of data to a tuple of functions?

I have the following Python code: data = ['1', '4.6', 'txt'] funcs = [int, float, str] How to call every function with data in corresponding index as an argument to the function? Now I'm using the code: result = [] for i, func in enumerate(funcs): result.append(func(data[i])) map(funcs, data) don't work with tuple of function...

value_type size

is there any ways of retrieving the number of elements in typename X::value_type where X is a vec of tuples? thanks ...

Why does this cause a syntax error?

Hello, In python, I wrote this: bvar=mht.get_value() temp=self.treemodel.insert(iter,0,(mht,False,*bvar)) I'm trying to expand bvar to the funtion call as arguments. But then it return, File "./unobsoluttreemodel.py", line 65 temp=self.treemodel.insert(iter,0,(mht,False,*bvar)) ^ ...

Newbie f# question

I have a simple function call takes two tuples. Getting compiler error on type: module test open System.IO open System let side (x1,y1) (x2,y2) : float = Math.Sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)) let a = side ( 2s, 3s ) ( 1s, 2s ) Error 2 The type 'float' does not match the type 'int16' Not sure where it goes wrong. ...

Declaring Tuple in Xaml

Is there a way to declare a tuple in xaml so I can use it as a converterparameter? ...

Erlang BIF's to delete tuples in list

How can I delete a tuple with key from a list? Ex: TupleList = [ {apple, {0,0,0}}, {orange, {0,0,0}}, {bannana, {0,0,0}}] Then I need to delete the tuple whos key matches orange. So I should get back [ {apple, {0,0,0}}, {bannana, {0,0,0}}] Im looking for a BIF instead of a function as I am using right now. Thanks and Regards ...

Python - List Mapping

Hey, I have several lists that I would like to map together, but I can't quite work my head around how to do it. I am scraping a live feed of Horse Racing results. The feed only lists the course/time once and three horses and their positions (top three) OR four horses and blank (i.e. "") positions IF the race was abandoned. These are t...

Turning boost::tuples::cons<...> back into the corresponding boost::tuple<...>

For a little library project I'm using boost::tuple. Right now, I'm facing the problem of turning a "cons list" I operated on via metaprogramming back to a boost::tuple<...> type. The "dirty" solution would be to provide lots of partial specialications a la template<class T> struct id{typedef T type;}; template<class TL> struct type_li...

How is std::tuple implemented?

I'd like to know how are tuple implemented in standard library for C++0x. I tried to read description in libstdc++ manual and then read template listing, but it's really hard to understand how it works, especially when reading code. Can someone explain me in few sentences the idea of tuple implementation? I want to know this, because I ...