tuple

Inserting an item in a Tuple

Yes, I understand tuples are immutable but the situation is such that I need to insert an extra value into each tuple. So one of the items is the amount, I need to add a new item next to it in a different currency, like so: ('Product', '500.00', '1200.00') Possible? Thanks! ...

Use 'map' and stuff on Scala Tuples?

'map' preserves the number of elements, so using it on a Tuple seems sensible. My attempts so far: scala> (3,4).map(_*2) error: value map is not a member of (Int, Int) (3,4).map(_*2) ^ scala> (3,4).productIterator.map(_*2) error: value * is not a member of Any (3,4).productIterator.map(_*2) ...

Python 3.1.1 Problem With Tuples

This piece of code is supposed to go through a list and preform some formatting to the items, such as removing quotations, and then saving it to another list. class process: def rchr(string_i, asciivalue): string_o = () for i in range(len(string_i)): if ord(string_i[i]) != asciivalue: stri...

How would I find the highest/largest of something with relation algebra, domain relational calculus and tuple relational calculus

This is part of a homework assignment. I've got several questions asking find the eid of the employee with the highest salary, or 2nd highest salary. Find the pilot that is certified for the most aircrafts. I don't have any idea on how to do it. There aren't any examples in the chapter, and google is proving less that helpful. If someone...

Print Tuple Index in Python

This question falls into the "yes - this works, yes - this is ugly, yes - there is probably a better way" category. I want to use a regular expression to pull groups out of a match and then print the group number and the group value. It is to show someone how regular expressions work and to keep track of the values of each group. The cod...

What exactly are tuples in Python?

I'm following a couple of Pythone exercises and I'm stumped at this one. # C. sort_last # Given a list of non-empty tuples, return a list sorted in increasing # order by the last element in each tuple. # e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields # [(2, 2), (1, 3), (3, 4, 5), (1, 7)] # Hint: use a custom key= function to extract th...

Dictionaries with tuples that have lists as values.

How can i have a tuple that has a list as a value. F.x. if i want to have a structure like this. ( Somechar , Somelist[] ) And how would i iterate through a dictionary of these things? ...

Better use a tuple or numpy array for storing coordinates

Hi, I'm porting an C++ scientific application to python, and as I'm new to python, some problems come to my mind: 1) I'm defining a class that will contain the coordinates (x,y). These values will be accessed several times, but they only will be read after the class instantiation. Is it better to use an tuple or an numpy array, both in...

Using Python tuples as vectors

I need to represent immutable vectors in Python ("vectors" as in linear algebra, not as in programming). The tuple seems like an obvious choice. The trouble is when I need to implement things like addition and scalar multiplication. If a and b are vectors, and c is a number, the best I can think of is this: tuple(map(lambda x,y: x +...

Scala: how can I sort an array of tuples by their second element?

Hi all, is there a way in Scala to sort an array of tuples using and arbitrary comparison function? In particular I need to sort and array of tuples by their second element, but I wanted to know a general technique to sort arrays of tuples. Thanks! ...

How can I convert this string to list of lists?

Hi, what I'm trying to do is.. if a user types in [[0,0,0], [0,0,1], [1,1,0]] and press enter, the program should convert this string to several lists; one list holding [0][0][0], other for [0][0][1], and the last list for [1][1][0] I thought tuple thing would work out but no luck... :( I started python yesterday -- (I'm C / C++ guy....

efficiently list items in tuples starting at end

I'd like to list the items in a tuple in Python starting with the back and go to front. Similar to: foo_t = tuple(int(f) for f in foo) print foo, foo_t[len(foo_t)-1] ... I believe this should be possible without Try ...-4, except ...-3. Thoughts? suggestions? ...

Using Tuples in Java

My Hashtable in Java would benefit from a value having a tuple structure. What data structure can I use in Java to do that? Hastable<Long, Tuple<Set<Long>,Set<Long>>> table = ... ...

Type problem when including tuple

I'm using Visual Studio 2008 with Feature Pack 1. I have a typedef like this typedef std::tr1::tuple<std::string, std::string, int> tileInfo with a function like this const tileInfo& GetTile( int x, int y ) const. In the implementation file the function has the exact same signature (with the added class name qualifier) and I am gettin...

Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items

When I create strongly typed View in Asp.net mvc 2, .net 4.0 with model type Tuple I get error when Tuple have more than 4 items example 1: type of view is Tuple<string, string, string, string> (4-tuple) and everything works fine view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web....

haskell sorting

Hello, How can it be done in most simply way to write (or maybe there is something embedded in haskell) function which takse as arguments list of tuples (String, Int) and Int x and return top x tuples as list according to x value. I wonder if its possible to write a function which also takes 3 argument which is the name of (or index) ...

How can I turn a single element in a list into multiple elements using Python?

I have a list of elements, and each element consists of four seperate values that are seperated by tabs: ['A\tB\tC\tD', 'Q\tW\tE\tR', etc.] What I want is to create a larger list without the tabs, so that each value is a seperate element: ['A', 'B', 'C', 'D', 'Q', 'W', 'E', 'R', etc.] How can I do that in Python? I need it for my cou...

get a simple list from sqlite in python (not a list of tuples)

it's annoying how sqlite always returns a list of touples! i can see the why this is necessary, but when i am querying a single column, how do i get a plain list? e.g cursor.fetchall() returns [(u'one',), (u'two',), (u'three',)] from this, how do i get the simple list [u'one', u'two', u'three']? ...

Is C# 4.0 Tuple covariant

(I would check this out for myself, but I don't have VS2010 (yet)) Say I have 2 base interfaces: IBaseModelInterface IBaseViewInterface And 2 interfaces realizing those: ISubModelInterface : IBaseModelInterface ISubViewInterface : IBaseViewInterface If I define a Tuple<IBaseModelInterface, IBaseViewInterface> I would like to set t...

Python: Access dictionary value inside of tuple and sort quickly by dict value

I know that wasn't clear. Here's what I'm doing specifically. I have my list of dictionaries here: dict = [{int=0, value=A}, {int=1, value=B}, ... n] and I want to take them in combinations, so I used itertools and it gave me a tuple (Well, okay it gave me a memory object that I then used enumerate on so I could loop over it and enume...