def count_types(lst: List[Any]) -> List[int]: """ Given a list of random types, return the number of occurrences of each type, in the form of a list, in the order that they were first seen. For example, if the input ['str1', 1, 'str2'], the output would be [2, 1], as a string type appears first, and occurs twice in the list. An integer type appears next, and only occurs once in the list. Another example could be [True, 'str1', 1, False, 'str2', True], where the output would be [3, 2, 1], as a boolean type appears first, and occurs three times in the list. A string appears next, and occurs twice in the list. Finally, an integer appears next, and occurs once in the list. """ don't use any import, dictionaries, or dictionary methods or try-except statements
def count_types(lst: List[Any]) -> List[int]:
"""
Given a list <lst> of random types, return the number of occurrences of
each type, in the form of a list, in the order that they were first seen.
For example, if the input ['str1', 1, 'str2'], the output would be [2, 1],
as a string type appears first, and occurs twice in the list. An integer
type appears next, and only occurs once in the list.
Another example could be [True, 'str1', 1, False, 'str2', True], where the
output would be [3, 2, 1], as a boolean type appears first, and occurs
three times in the list. A string appears next, and occurs twice in the
list. Finally, an integer appears next, and occurs once in the list.
"""
don't use any import, dictionaries, or dictionary methods or try-except statements.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images