0
1
2
3
4
for loopfor in range():for x in list:count_vowelsstring argumentdictionarydictionary with the count of every lowercase vowel in stringdef count_vowels(string):
counts = {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0}
for char in string:
if char in counts:
counts[char] += 1
return counts
def main():
assert count_vowels("") == {"a": 0, "e": 0, "i": 0, "o": 0, "u": 0}
assert count_vowels("banana") == {"a": 3, "e": 0, "i": 0, "o": 0, "u": 0}
print("Passed all tests.")
main()Passed all tests.
count_charsstring argumentdictionarydictionary with the count of every characters in stringtally_negativesnumbers as argumentnumbers to its frequency in numbersTest cases:
Submit your tally_negatives function to Gradescope for attendance.
Name your file tally_negatives.py
for k in dictionary:We can use .values() to get only the values in a dictionary:
dict_values([10, 25, 27, 10, 5])
We can use .keys() to get only the keys in a dictionary:
dict_keys(['A', 'B', 'C', 'D', 'E'])
We can use .items() to get tuples for keys and values:
for x in list10
25
27
10
5
for key, value in dictionary.items()keys_and_valuesdictionary as argumentdictionaryTest cases:
merge_dictionariesdict_1 and dict_2dict_1, by adding to it all key-values pairs in dict_2.update()Test cases: