"""
Create a function called
arguments:
- a dictionary, which maps integer numbers to words, K:W (but could be empty)
- a number describing the start of a range (INclusive), L
- a number describing the end of the ranage (EXclusive), U
The function must return a new dictionary, where:
1. The result keys (KR) would be the integer numbers within the range,
confined between L and U.
2. The corresponding values would be composed of the values of the
concatenated M words, whose key divides the result key with no remainder
(in other words, where KR modulo K = 0).
3. The order of the concatenation is important, and it should follow the
ascending order of the keys (K) in the input dict
4. If none of the keys K divides the KR exactly, then resulting value should
be '' (an emptystring).
Please check the given example.
In addition, the function should have the following string as its documentation:
Advanced version of FizzBuzz solver
Example:
fizz_buzz({3:'Fizz', 5:'Buzz'}, 2, 16) ->
{
1:'',
2:'',
3:'Fizz', # 3 is divisble by 3 with a remainder of 0, so we return Fizz
4:'',
5:'Buzz', # 5 is divisble by 5 with a remainder of 0, so we return Buzz
6:'Fizz', # 6 is divisble by 3 with a remainder of 0, so we return Fizz
7:'',
8:'',
9:'Fizz', # 9 is divisble by 3 with a remainder of 0, so we return Fizz
10:'Buzz', # 10 is divisble by 5 with a remainder of 0, so we return Buzz
11:'',
12:'Fizz', # 12 is divisble by 3 with a remainder of 0, so we return Fizz
13:'',
14:'',
15:'FizzBuzz', # 15 is divisible by both 3 and 5, so we return FizzBuzz
# Note that the order should always be "Fizz" first and
# "Buzz" second, due to "Fizz" having a lower value (3)
# in the input dictionary (compared to 5 for "Buzz")
}
"""
how do i append new items to a dictionary
Create a function called
fizz_buzz_advanced
. The function should take 3arguments:
- a dictionary, which maps integer numbers to words, K:W (but could be empty)
- a number describing the start of a range (INclusive), L
- a number describing the end of the ranage (EXclusive), U
The function must return a new dictionary, where:
1. The result keys (KR) would be the integer numbers within the range,
confined between L and U.
2. The corresponding values would be composed of the values of the
concatenated M words, whose key divides the result key with no remainder
(in other words, where KR modulo K = 0).
3. The order of the concatenation is important, and it should follow the
ascending order of the keys (K) in the input dict
4. If none of the keys K divides the KR exactly, then resulting value should
be '' (an emptystring).
Please check the given example.
In addition, the function should have the following string as its documentation:
Advanced version of FizzBuzz solver
Example:
fizz_buzz({3:'Fizz', 5:'Buzz'}, 2, 16) ->
{
1:'',
2:'',
3:'Fizz', # 3 is divisble by 3 with a remainder of 0, so we return Fizz
4:'',
5:'Buzz', # 5 is divisble by 5 with a remainder of 0, so we return Buzz
6:'Fizz', # 6 is divisble by 3 with a remainder of 0, so we return Fizz
7:'',
8:'',
9:'Fizz', # 9 is divisble by 3 with a remainder of 0, so we return Fizz
10:'Buzz', # 10 is divisble by 5 with a remainder of 0, so we return Buzz
11:'',
12:'Fizz', # 12 is divisble by 3 with a remainder of 0, so we return Fizz
13:'',
14:'',
15:'FizzBuzz', # 15 is divisible by both 3 and 5, so we return FizzBuzz
# Note that the order should always be "Fizz" first and
# "Buzz" second, due to "Fizz" having a lower value (3)
# in the input dictionary (compared to 5 for "Buzz")
}
"""
def fizz_buzz_advanced(db,ll,ul): for i in range(ll,ul): for k,v in db.items(): p = i%k ndb = {} if (p == 0): n = v ndb.update({i:n}) else: n = '' ndb.update({i:n}) print ndb db = {3:'Fizz', 5:'Buzz'} ll = 2 ul = 7 fizz_buzz_advanced(db,ll,ul)my question:
how do i append new items to a dictionary