Deciphering collections: defaultdict and Counter

Report a typo

Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Consider the following Python code where defaultdict and Counter from the collections module are used on a complex dataset of people's information:
import collections

data = [('John', 'Male', 28), ('Anna', 'Female', 24), ('John', 'Male', 28), ('Anna', 'Female', 24), ('Mike', 'Male', 30), ('Anna', 'Female', 25)]

# Defaultdict example
data_defaultdict = collections.defaultdict(list)
for name, gender, age in data:
    data_defaultdict[(name, gender)].append(age)

# Counter example
data_counter = collections.Counter([(name, gender) for name, gender, age in data])

print(data_defaultdict)
print(data_counter)


What would be the output of this code?

Select one option from the list

Create a free account to access the full topic