Linked Questions

1 vote
2 answers
5k views

I have some code to test other codes that I've written(in ipython notebook). print_closest = lambda w, wl: print('{}: {} ({})'.format(w, *closest_match(w, wl))) This is the code I have and it works ...
jsh114's user avatar
  • 43
2 votes
0 answers
7k views

I want to pass a function/lambda to a method and then call it in python 2.7: def foo(f): f() I tried many ways but didnt find the correct syntax. For example this foo(lambda: print("hallo")) ...
463035818_is_not_an_ai's user avatar
529 votes
16 answers
904k views

In Python 2.6, I want to do: f = lambda x: if x==2 print x else raise Exception() f(2) #should print "2" f(3) #should throw an exception This clearly isn't the syntax. Is it possible to ...
Guy's user avatar
  • 14.9k
167 votes
22 answers
263k views

I have a list of lists: lst = [[567, 345, 234], [253, 465, 756, 2345], [333, 777, 111, 555]] I want map lst into another list containing only the second smallest number from each sublist. So the ...
ottodidakt's user avatar
  • 3,761
18 votes
6 answers
11k views

For a normal function, map works well: def increment(n): return n+1 l = [1, 2, 3, 4, 5] l = map(increment, l) print l >>> [2, 3, 4, 5, 6] However, if it's print being put inside the map ...
clwen's user avatar
  • 21k
16 votes
2 answers
30k views

The documentation for threading.Thread(target=...) states that target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called. I usually use it like ...
WoJ's user avatar
  • 30.6k
11 votes
3 answers
30k views

I am learning Spark in Python and wondering can anyone explain the difference between the action foreach() and transformation map()? rdd.map() returns a new RDD, like the original map function in ...
Chenxi Zeng's user avatar
3 votes
2 answers
4k views

I know how fierce the SO community is so I'll try my best to keep the question minimal, complete and verifiable. What I simply want to know is can monkey patching be used to replace the definition of ...
Vivek Shankar's user avatar
4 votes
2 answers
4k views

This: add = lambda x, y: x += y Gives: SyntaxError: invalid syntax My task is to be able to mullitply or add every number between 1-513 with 1 function and 2 lambda functions. So if you have any ...
Filip Willemsen's user avatar
2 votes
3 answers
1k views

Lets say we have the following: my_condition = True print('AAA' if my_condition else 'BBB') The output would be: AAA Conversely, if my_condition became False: my_condition = False print('AAA' if ...
holaymolay's user avatar
3 votes
1 answer
1k views

How can I code a OneLineListItem in KivyMD to print its "text" on a console? I came up with something like this: [...] item = OneLineListItem(text="DEMO", on_press= lambda x: ??????...
bobk810i's user avatar
0 votes
2 answers
631 views

how to use map() instead of the following nested for loop the idea to not use for loop :) def f(matrix): r, c = np.shape(array) for col in range(0,c): for row in range(0,r): ...
maryam_musalam's user avatar
0 votes
1 answer
531 views

letters = ['a', 'b', 'c', 'd', 'e', 'f'] list(filter(lambda x : print(x) if 'e' in x ,letters)) SyntaxError: invalid syntax
Prathamesh Kadam's user avatar
0 votes
3 answers
420 views

lambda i: print(i),["%d even"% i if i % 2 == 0 else "%d odd"% i for i in random.sample(range(100), 10)] What is wrong with this code, it is not printing anything. If I try to print by using another ...
user1423015's user avatar
-1 votes
1 answer
197 views

For code completion with Scintilla.Net i need the list of keywords that are valid in an expression. You can get all keywords via the "keyword" module, but for example "raise" and "print" cannot be ...
Rauhotz's user avatar
  • 8,180

15 30 50 per page