tuples

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: Why is comparison between lists and tuples not supported?

When comparing a tuple with a list like ... >>> [1,2,3] == (1,2,3) False >>> [1,2,3].__eq__((1,2,3)) NotImplemented >>> (1,2,3).__eq__([1,2,3]) NotImplemented ... Python does not deep-compare them as done with (1,2,3) == (1,2,3). So what is the reason for this? Is it because the mutable list can be changed at any time (thread-safety ...

In Haskell, how can I use the built in sortBy function to sort a list of pairs(tuple)?

I am a beginner in Haskell so please bear with me. (Just started learning yesterday!) How can I sort a list of tuples primarily by their first components (highest to smallest) and secondarily by their second components (smallest to highest)? A sample input/output would be: [(1, "b"), (1, "a"), (2, "b"), (2, "a")] (input) [(1, "a"), (2,...

How do I ensure I always get a list of matches from Python's Regular Expressions?

I'm trying to pull some information (no recursion necessary) from a jsp page (malformed xml) similar to this: <td> <html:button ...></html:button> <html:submit ...></html:submit></td> And a regex: <html:(button|submit|cancel)[\s\S]*?</html:(button|submit|cancel)> re.findall() is giving me a list of tuples, like so: [('button','but...

Scala: "using" keyword

i've defined 'using' keyword as following: def using[A, B <: {def close(): Unit}] (closeable: B) (f: B => A): A = try { f(closeable) } finally { closeable.close() } i can use it like that: using(new PrintWriter("sample.txt")){ out => out.println("hellow world!") } now i'm curious how to define 'using' keyword to take any number...

Convert list in tuple to numpy array?

I have tuple of lists. One of these lists is a list of scores. I want to convert the list of scores to a numpy array to take advantage of the pre-built stats that scipy provides. In this case the tuple is called 'data' In [12]: type data[2] -------> type(data[2]) Out[12]: <type 'list'> In [13]: type data[2][1] -------> type(data[2][1]...

Python - merge items of two lists into a list of tuples

What's the pythonic way of achieving the following? list_a = [1, 2, 3, 4] list_b = [5, 6, 7, 8] #Need to create a of tuples from list_a and list_b list_c = [(1,5), (2,6), (3,7), (4,8)] Each member of list_c is a tuple, whose first member is from list_a and the second is from list_b. ...

Emit Tuples From Erlang Views In CouchDB

CouchDB, version 0.10.0, using native erlang views. I have a simple document of the form: { "_id": "user-1", "_rev": "1-9ccf63b66b62d15d75daa211c5a7fb0d", "type": "user", "identifiers": [ "ABC", "DEF", "123" ], "username": "monkey", "name": "Monkey Man" } And a basic javascript design documen...

Python: Lits containg tuples and long int.

I have a list containing a tuples and long integers the list looks like this: table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] How do i convert the table to look like a formal list? so the output would be: table = ['1','1','1','2','2','2','3','3'] For information purposes the data was obtained from a mysql datab...

Python: Removing tuples from a list of lists

I have a list of lists containing tuples: [[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)] how do i edit the list so the list looks like: l = [[1][2][3][4][5]] ...

how to get the index or the element itself of an element found with "if element in list"

Hey, Does a direct way to do this exists? if element in aList: #get the element from the list I'm thinking something like this: aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 ...

XOR swap algorithm in python?

I tried to implement XOR swap in python. x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) OUTPUT: 30 , 30 I am not new to python but I am unable to explain this output. It should have been 20,10. What is going on under the hood? ...

Sort a list of tuples without case sensitivity

How can I efficiently and easily sort a list of tuples without being sensitive to case? For example this: [('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] Should look like this once sorted: [('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] The regular lexicographic sort will put 'A' before 'a' and yield this: [('A', 'b'), ('a', 5), ('...

Python 3 with the range function

I can type in the following code in the terminal, and it works: for i in range(5): print(i) And it will print: 0 1 2 3 4 as expected. However, I tried to write a script that does a similar thing: print(current_chunk.data) read_chunk(file, current_chunk) numVerts, numFaces, numEdges = current_chunk.data print(current_chunk.da...

Different results when applying function to equal values

I'm just digging a bit into Haskell and I started by trying to compute the Phi-Coefficient of two words in a text. However, I ran into some very strange behaviour that I cannot explain. After stripping everything down, I ended up with this code to reproduce the problem: let sumTup = (sumTuples∘concat) frequencyLists let sumFixTup = (13...

Python: Converting a tuple to a string

Given this : import os import subprocess def check_server(): cl = subprocess.Popen(["nmap","10.7.1.71"], stdout=subprocess.PIPE) result = cl.communicate() print result check_server() check_server() returns this tuple: ('\nStarting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:26 EDT\nInteresting ports on 10.7.1....

How to simulate tuples and sets in C#?

I want to use some features of python like as Tuples and Sets in c#. should I implement them? or there are already implemented? could anybody knows a library of dynamic data structures for .net languages? ...

How do .net 4.0 [named] tuples work under the hood?

I suspect that there is a lot of work done at low level. when names are used for tuple elements, do auto-properties get created? Thanks. ...

Scala's tuple unwrapping nuance

I've noticed the following behavior in scala when trying to unwrap tuples into vals: scala> val (A, B, C) = (1, 2, 3) <console>:5: error: not found: value A val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value B val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value C ...

Scala return type for tuple-functions

Hello Guys, I want to make a scala function which returns a scala tuple. I can do a function like this: def foo = (1,"hello","world") and this will work fine, but now I want to tell the compiler what I expect to be returned from the function instead of using the built in type inference (after all, I have no idea what a (1,"hello","w...