1
vote
1answer
26 views

Why isn't this working? (python-constraint)

My code from constraint import * abc = ((0, 1, 1), (1, 0, 0)) #((a1,b1,c1),(a2,b2,c2)) lim=10 #arbitrary problem = Problem() problem.addVariable("u", range(-lim,lim+1)) problem.addVariable("v", ...
7
votes
3answers
167 views

python - can lambda have more than one return

I know lambda doesn't have a return expression. Normally def one_return(a): #logic is here c = a + 1 return c can be written: lambda a : a + 1 How about write this one in a lambda ...
0
votes
2answers
55 views

How to pass a parameter in a lambda function in python?

I want to set colors of an object, and don't want to create 10 functions for every color. So, I just want to declare the colors and create 10 buttons and one function. Error message is: ...
0
votes
2answers
40 views

Python, cPickle, pickling lambda functions

I have to pickle an array of objects like this: import cPickle as pickle from numpy import sin, cos, array tmp = lambda x: sin(x)+cos(x) test = array([[tmp,tmp],[tmp,tmp]],dtype=object) pickle.dump( ...
0
votes
2answers
47 views

Python — confused by numpy's piecewise function

I'm trying to implement a piecewise function in Python. Since I'm using quite a few tools from numpy, I simply import everything from it (i.e. from numpy import *). My piecewise function is defined as ...
0
votes
4answers
31 views

python lambda function of 0 arity

is it possible to write the following using Python's lambda notation? def no(): return the closest i can without a sytax error is no = lambda _: no which has the following property: >>> ...
0
votes
3answers
47 views

Assign variable to local scope of function in Python

I'd like to assign a variable to the scope of a lambda that is called several times. Each time with a new instance of the variable. How do I do that? f = lambda x: x + var.x - var.y # Code needed ...
0
votes
1answer
37 views

will lambda func be 'cached'/remembered [duplicate]

map( lambda x: len(x), aLotOfData) I am writing some code similar to above, will it actually be slower if I put in the lambda def in the same line? or I should assign to to a variable f to avoid ...
0
votes
1answer
43 views

simplify this python generation

I am new to python. Is there a way to simplify this: def getDivs(): divs = soup.findAll(name = "div", attrs = {"class" : "resultCell"}, recursive = True) for div in divs: h2 = ...
0
votes
1answer
31 views

Python lambdas in Jinja2

I use Jinja2 as a website template engine, and all helper functions used in templates I've implemented as macros, but for one. This is it's Python code: def arrow_class_from_deg(angle): if angle ...
-2
votes
1answer
37 views

How can I use lambda complete this function?

I want to use lambda to finish the following function: for i in range(0, len(testingList)): testingList[i] = testing[i][1:-1] I don't know how to use lambda to build it. Thank you very much.
0
votes
3answers
49 views

Returning a dictionary based on a condition

I am trying to use a lambda or other python feature to return an dictionary if a condition is met, or none if not. myDict = None myDict = lambda c: {} if not myDict else myDict Clearly, this not ...
0
votes
1answer
41 views

Python “with” Keyword in Lambda Functions

How is Python's with keyword expressed in a lambda function? Consider the following: def cat (filename): with open(filename, 'r') as f: return f.read() A failed attempt at a lambda ...
0
votes
2answers
41 views

tkinter button commands with lambda in Python

ive tried searching for a solution but couldn't find one that works. I have a 2d list of tkinter Buttons, and i want to change their Text when it is clicked by the mouse. I tried doing this: def ...
1
vote
3answers
96 views

TypeError: <lambda>() takes no arguments (1 given)

I am a newbie to python programming and am still trying to figure out the use of lambda. Was worrking on some gui program after much googling i figured that i need to use this for buttons to work as i ...

1 2 3 4 5 21
15 30 50 per page