Skill Test #5 Practice Questions

Skill 1 (Time Complexity):


For this skill, you will analyze blocks of code and identify their time complexity using Big-O notation. Refer to lab06 for practice.

Skill 2 (Args + Default Args):


1. Write a function freqs that takes in an arbitrary number of integers and returns a dictionary mapping each integer to its frequency.

2. Write a function keep that takes in an arbitrary number of integers and a default argument keep_evens. If keep_evens is True, return a list of the even numbers; otherwise, return a list of the odd numbers. Make sure to fill out the function header.

Skill 3 (Kwargs):


1. Write a function oldest that takes in keyword arguments of the form name = age, and returns the name of the oldest person. If there is a tie, return the person whose name appears last among the keyword arguments.

2. Write a function reconstruct that takes in keyword arguments of the form string = frequency, and returns a list where each string appears frequency times.

Skill 4 (Recursion):


1. Given an integer n, write a function factorial that recursively computes n!. You may assume n is greater than 0.

2. Write a function calc_log2 that recursively computes log2(num). You may assume num is a power of 2.

3. Given a list lst, write a function count that recursively counts the number of elements in lst.

4. Write a function count_ints that recursively counts how many elements in lst are integers.

5. Write a function banned that recursively checks whether banned_word appears in the list words.

6. Write a function palindrome that recursively checks whether a string is a palindrome (reads the same forward and backward). Refer to doctests.

7. Write a function evens_odds that recursively computes the difference between the sum of evens and the sum of odds in a list of integers, nums. Refer to doctests.

Requirements: Recursion only (no loops).

Code Editor

• skill_test_#5_practice_questions.py
Python UTF-8
Saved Ln 1, Col 1

Console

Output
Press Cmd/Ctrl + Enter to run tests
Code output and test results will appear here...