Is there a way to expand a Python tuple into a function - as actual parameters?
For example, here expand() does the magic:
tuple = (1, "foo", "bar")
def myfun(number, str1, str2):
return (number * 2, str1 + str2, str2 + str1)
myfun(expand(tuple)) # (2, "foobar", "barfoo")
I know one could define myfun as "myfun((a, b, c))", but...
For a remoting scenario, the result would be very good to receive as an array or list of Tuple objects (among benefits being strong typing).
Example: dynamically convert SELECT Name, Age FROM Table => List<Tuple<string,int>>
Question: are there any samples out there that, given an arbitrary table of data (like SQL resultset or CSV ...
I've got a python function that should loop through a tuple of coordinates and print their contents:
def do(coordList):
for element in coordList:
print element
y=((5,5),(4,4))
x=((5,5))
When y is run through the function, it outputs (5,5) and (4,4), the desired result. However, running x through the function outputs 5 and ...
I don't understand why the following case doesn't match. Null should be an instance of Any, but it doesn't match. Can someone explain what is going on?
val x = (2, null)
x match {
case (i:Int, v:Any) => println("got tuple %s: %s".format(i, v))
case _ => println("catch all")
}
prints catch all
Thanks.
...
I've read many times that
Assemblies generated from F# or any other .NET language are (almost) indistinguishable.
I was then experimenting with F# and C# interop on .NET 4 (beta 2). I created a new solution, and a C# project, with the following class:
public class MyClass {
public static int Add(int a, int b) { return a + b; }...
What's the best one-liner replacement for the code below? I'm sure there's a smarter way.
choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
some_int = 2
for choice in choices:
if choice[0] == some_int:
label = choice[1]
break;
# label == 'TWO'
...
Hi, I am building a class that has a mapping of strings to integers. So if I have 3 apples I would have a mapping of apples to 3.
I need to write a class that sorts the name of the objects by decreasing numbers.
So if I have
(apples, 3)
(oranges, 2)
(bananas, 5)
I will get
(bananas, 5), (apples, 3), (oranges 2)
I was wondering if t...
Hello StackOverflow,
I have problems with writing an specific application in a scala-esque and elegant way. I tried this for some time now, but I cannot find a "good" solution to this Problem:
Given that I have the following List:
List("foo", "bar", "baz", "blah")
I want to Iterate over this list, not only giving me the current elem...
I am wanting to zip up a list of entities with a new entity to generate a list of coordinates (2-tuples), but I want to assure that for (i, j) that i < j is always true.
However, I am not extremely pleased with my current solutions:
from itertools import repeat
mems = range(1, 10, 2)
mem = 8
def ij(i, j):
if i < j:
return (i, ...
I want to save the results of my function binomal_aux to a tuple but I don't have an idea how to, here is my code I have right now.
def binomal (n):
i=0
for i in range(n):
binomal_aux(n,i) #want this to be in a tuple so, binomal (2) = (1,2,1)
return
def binomal_aux (n,k):
if (k==0):
return 1
elif...
I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.
Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in the first place?
Immutabilit...
Basically I'm looking to take the output of Seq.Windowed which returns a sequence of arrays and turn it into a sequence of tuples
so I want to take this
[[|1;2;3|];[|4;5;6|]]
and turn it into
[(1,2,3);(4,5,6)]
Thanks in advance.
...
Is it possible to assign tuple members in parallel in Scala. if not is there another technique to accomplish something similar?
val players = List(
new Player("Django Reinhardt", 42),
new Player("Sol Hoopii", 57),
new Player("Marc Ribot", 64)
)
val winners, losers = players.partition(p => p.score > 50)
// winners = List...
I've got a list of tuples extracted from a table in a DB which looks like (key , foreignkey , value). There is a many to one relationship between the key and foreignkeys and I'd like to convert it into a dict indexed by the foreignkey containing the sum of all values with that foreignkey, i.e. { foreignkey , sumof( value ) }. I wrote s...
I have a curried function that I'd like it to support different types of parameters, that are not on a inheritance relationship:
type MyType1 = A | B of float
type MyType2 = C | D of int
What I tried to do is:
let func x y =
match (x, y) with
| :? Tuple<MyType1, MyType1> -> "1, 1"
| _ -> "..."
However this is not possib...
TypeError: unsupported operand type(s) for /: 'tuple' and 'tuple'
I'm getting above error , while I fetched a record using query "select max(rowid) from table"
and assigned it to variable and while performing / operation is throws above message.
How to resolve this.
...
This is ugly. How would you do it?
import datetime
t= (2010, 10, 2, 11, 4, 0, 2, 41, 0)
dt = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], t[6])
Thanks in advance.
...
Hi there. I'm trying my best to figure out a succinct, straightforward widget, using standard UI widgets available in any toolkit (e.g., checkboxes, radio buttons, or listboxes), that could model a true/false/null value.
Why am I trying to do this? I'm storing a tree in a database (go ahead, criticise me for storing hierarchical informa...
I have a list of tuples representing x,y points. I also have a list of values for each of these points. How do I combine them into a list of lists (i.e one entry for each point [x,y,val]) or a list of tuples?
Thanks
...
I have variable r=(u'East london,London,England', u'Mr.Baker in East london (at 2010-02-21 15:25:27.0)') in this format from webservice as a output from small program. How can I print these tuple data as normal string like:
East london,London,England Mr.Baker in East london (at 2010-02-21 15:25:27.0)
can anybody help me out of thi...