Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Does C actually need ; {}[]?

Name: Anonymous 2017-02-28 4:18

Does it?

Name: Anonymous 2017-02-28 4:38

saw this on reddit: http://www.theodo.fr/blog/2017/02/i-challenge-you-to-debug-those-7-lines-of-code-under-9-minutes/

def foo(a, methods=[]): # methods defaults to [] if not specified
for i in range(3):
# Append an anonymous function, which returns `x + i`
# when given `x`
methods.append(lambda x: x + i)

sum_methods = 0
# For each function `method` of in `methods`, sum `method(a)`
for method in methods:
sum_methods += method(a)
return sum_methods


You expect your function to output the following:
foo(0) = (0 + 0) + (0 + 1) + (0 + 2) = 3
foo(1) = (1 + 0) + (1 + 1) + (1 + 2) = 6
foo(2) = (2 + 0) + (2 + 1) + (2 + 2) = 9
foo(2, [lambda x: x]) = ((2)) + ((2 + 0) + (2 + 1) + (2 + 2)) = 11

Simple, right? Let’s try it in our terminal.
foo(0)
6
foo(1)
18
foo(2)
36
foo(2, [lambda x: x])
14

Well, there seems to be a minor error. But wait, could we have missed something? Let’s check again.
foo(0)
24
foo(1)
45
foo(2)
72

WHAT.

THE.

how much abuse do you have to take before you accept that he doesn't love you?

how much FORCED INDENTATION OF CODE is it going to take before thread over

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List