question 166 Nested Data Structures · medium
Every new account gets everyone's tags
Accounts start from shared DEFAULTS. After a few sign-ups, support notices that each new account shows the tags of every earlier account, and switching SMS on for one person switched it on for others. Fix new_account so every account owns its own settings and DEFAULTS never changes.
Function
new_account(user_id, tags)Returnsa new dictionary:
user_id, notify ({"email": True, "sms": False}) and tags (the given tags, in order)Rulestwo accounts never share their
notify dictionary or their tags list, with each other, with DEFAULTS or with the list passed inKeep
DEFAULTS and the function's name and result; only the bug should changeExamples
callnew_account('u-ana', ['beta'])returns{'user_id': 'u-ana', 'notify': {'email': True, 'sms': False}, 'tags': ['beta']}
callnew_account('u-ben', ['vip', 'eu'])returns{'user_id': 'u-ben', 'notify': {'email': True, 'sms': False}, 'tags': ['vip', 'eu']}
callnew_account('u-cai', [])returns{'user_id': 'u-cai', 'notify': {'email': True, 'sms': False}, 'tags': []}