KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
As a contrived example: myset = set(['a', 'b', 'c', 'd']) mydict = {item: (yield ''.join([item, 's'])) for item in myset} and list(mydict) gives: ['as', 'cs', 'bs', 'ds', {'a': None, 'b': None, 'c': None, 'd': None}] What happens here? What does yield do? And is this behavior consistent no matter what expression follows yield ? Note: I know that doing mydict = {item: ''.join([item, 's']) for item in myset} would give the dictionary {'a': 'as', 'b': 'bs', 'c': 'cs', 'd': 'ds'} , which seems to be what I am trying to do here.
Tags (comma-separated)
Save Edits
Cancel