- Create a function called
doubling
. It should take a number as input, and return the number multipled by two. - Create a function called
double
. It should take a list of numbers as input. Iterate through each element of the list, passing each to thedoubling
function. Return a dictionary with the elements of the list as keys and the associated doubled resuls as values - e.g., {2:4, 5:10}
-
-
Save mjhea0/847f12dd8adf6cf679f2 to your computer and use it in GitHub Desktop.
Great challenge!
Simple, but still good.
a = range(10); doubling = lambda x:2*x; double = lambda a: {x:doubling(x) for x in a}; print(double(a))
Am I doing thing right?
please don't post any answers/questions. email me at michael@realpython.com - thanks!
open("a variable", "w").write("[1,]")
double("this list")
for i in "the list":
pass
def doubling(number):
return number * 2
for element in "the for loop":
doubling(element)
open("a dictionary", "rw").write({"the original numbers": "the doubled results"})
@mjhea0 your specification is somewhat confusing:
- using terms such as "save" for storing variables
- mentioning things a for loop should do (pt 5) long after originally specified (pt 3)
- requesting calls to functions that were never defined, (pt 2)
- using sloppy definitions such as "this helper function"
Is this what you mean:
https://gist.github.com/graingert/7d5a592f8477d845569d
My go at writing clearer instructions. Note how the instructions start from the most atomic function the code performs (the double
procedure), but we give an overview of the task beforehand, so people know why they need to perform each step to complete the entire program.
Thanks. I updated the instructions. Yes, sometimes I can get in a bad habit of using jargon.
pythonic...
That was a fun way to test my knowledge of python. I'm only about halfway through the "Real Python" book and it took me about a half hour to get it right. I'm looking forward to more code challenges!