Combining argument types
Now you'll try to combine different argument types. Your task is to define the sort_all_types()
function. It takes positional and keyword arguments of variable size, finds all the numbers and strings contained within them, and concatenates type-wise the results. Use the sort_types()
function you defined before (available in the workspace). It takes a positional argument of variable size and returns a tuple containing a list of numbers and a list of strings (type sort_types?
to get additional help).
Keep in mind that keyword arguments of variable size essentially represent a dictionary and the sort_types()
function requires that you pass only its values.
Tip: To call the sort_types()
function correctly, you'd have to recall another usage of the *
symbol.
This exercise is part of the course
Practicing Coding Interview Questions in Python
Exercise instructions
- Define the arguments passed to the function (use any name you want).
- Find all the numbers and strings in the 1st argument.
- Find all the numbers and strings in the 2nd argument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define the arguments passed to the function
def sort_all_types(____, ____):
# Find all the numbers and strings in the 1st argument
nums1, strings1 = ____(____)
# Find all the numbers and strings in the 2nd argument
nums2, strings2 = ____(____.____)
return (nums1 + nums2, strings1 + strings2)
res = sort_all_types(
1, 2.0, 'dog', 5.1, num1 = 0.0, num2 = 5, str1 = 'cat'
)
print(res)