Feb-08-2020, 07:20 AM
How it works?
This can be written as dictionary comprehension as well:
for key in recs:
--> iterates over dictionary keys --> 1, 2, 3recs[key] =
--> assign/bound value to key in dictionary with name recs --> recs[1], recs[2], recs[3][item.replace('.com', '.org') for item in recs[key]]
--> new value which assigned/bound to key, created with list comprehension from existing value, in spoken languaga something like 'give item where .com is replaced with .org for every item in existing values'This can be written as dictionary comprehension as well:
>>> recs = {1: ['Susan Smith', '[email protected]'], ... 2: ['Cole Brown', '[email protected]'], ... 3: ['Sue John', '[email protected]']} >>> recs = {key: [item.replace('.com', '.org') for item in recs[key]] for key in recs} >>> recs {1: ['Susan Smith', '[email protected]'], 2: ['Cole Brown', '[email protected]'], 3: ['Sue John', '[email protected]']} >>> recs = {key: [item.replace('.org', '.com') for item in value] for key, value in recs.items()} >>> recs {1: ['Susan Smith', '[email protected]'], 2: ['Cole Brown', '[email protected]'], 3: ['Sue John', '[email protected]']}
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.