- Talk about problem
- Additional problem
- Survey/Questions
- Next time?
- 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 the doubling
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}
def double(array):
double_hash = {}
for num in array:
double_hash[num] = doubling(num)
return double_hash
def doubling(n):
n *= 2
return n
#-----driver code-----#
array = [1,2,3]
print double(array) == {1: 2, 2: 4, 3: 6}
array = [2,3,4]
print double(array) == {2: 4, 3: 6, 4: 8}
array = [3,4,5]
print double(array) == {3: 6, 4: 8, 5: 10}
def doubling(n):
return (n * 2)
def double(array):
return {num: doubling(num) for num in array}
def double(array):
return {num: num*2 for num in array}
- When you get into more complex OOP programming, one function should only do one thing. Get in the habit of that now. No matter how trivial. Sure, you could combine this into one function. But it will help you later on if you start thinking about breaking functions apart, logically.
- Think about your audience - Yourself, Future self, Other developers
- Write a function that takes a number as input and returns its equivalent value in roman numerals.
- Twitter API v1.1 - let's grab some tweets!
- Survey Link
- Questions!? RealPython.com Forum