def coldest_city(cities):
coldest = cities[0]
for city, temp in cities:
if temp < coldest[1]:
coldest = (city, temp)
return coldest[0]
cities = [("Tirane", 35), ("Prishtine", 29), ("Shkup", 30)]
coldest = coldest_city(cities)
Given the above script:
| What is the value of coldest: | ||
| What is the value of city during the first iteration of the loop: | ||
| What is the value of temp during the second iteration of the loop: |
Write a function that takes a dictionary and return True
if 10 exists in the d as key and as value. It returns False otherwise.
>>> exists({'a': 10, 2: 'a'})
False
>>> exists({'a': 'b', 10: 'a'})
False
>>> exists({10: 'b', 2: 10}, 'a')
True
>>> exists({'1': 'b', 10: 10}, 'a')
True
Write a function that takes a dictionary whose keys are numbers and returns their sum.
Example:
>>> get_sum({1: 'a', 2: 6, 12: 'po'})
15
Write a function that takes two lists, t1 and t2 returns a new list which is concatenation
of t1 and t2. t1 and t2 should not be modified.
>>> a, b = [1, 'ani'], [2]
>>> t = concat_lists(t1=a, t2=b)
>>> t
[1, 'ani', 2]
>>> a
[1, 'ani']
>>> b
[2]
Write a function that takes no arguments and returns a dictionary with three items, where keys are strings and values are lists.
Write a function, filter_allowed_words(words, allowed),
which returns a list of words that use only the allowed letters. Example:
>>> filter_allowed_words(['apple', 'banana', 'fig', 'grape'], 'aeplgr')
['apple', 'grape']
def dosmth(d, d1):
d.update(d1)
def dosmth1(d, k):
return d.setdefault(k, 'ani')
def dosmth2(d):
return d.get('pse', 'jo')
values = {'o': 'n', 'one': 22}
b = dosmth1(values, 'two')
c = dosmth(values, {'pse': 'perqef'})
d = dosmth2(values)
What is the value of the following variables at the end of the execution of the above script?
| values: | ||
| b: | ||
| c: | ||
| d: |
def dosmth(d, a):
return d.pop(a, None)
questions = {'ku': 'qaty', 'pse': 'sdi', 'jo be': 2}
a = dosmth(questions, 'ku')
b = dosmth(questions, 'ani')
What is the value of the following variables at the end of the execution of the above script?
| a: | ||
| b: | ||
| questions: |
Complete execution flow of the following program
def ani(word, char): index = 0 t = 0 while index < len(word): if word[index] == char: t = t + index index = index + 1 return t def add(word, ch1, ch2): return ani(word, ch1) + ani(word, ch2) d = add('sop', 'o', 'p')
Complete execution flow of the following program
def capitalize(s): return s[0].capitalize() + s[1:] a = capitalize('ani') b = capitalize('Pse') print(a, b)