python - Weird unpacking in list comprehension -


this question has answer here:

i watching a lecture david beazley. @ minute 23:20 "magic" unpacking having hard time understanding.

the "magic line"

fail = [ { **row, 'dba name': row['dba name'].replace("'",'').upper() } row in fail ] 

i have searched similar examples couldn't find any. can explain going on in code? can point me similar examples?

the snippet unpacking existing mapping row in dictionary literal while adding new element. simplified example demonstrating this:

>>> r = {'a':1, 'b':2}     >>> {**r, 'spam': 20} {'spam': 20, 'a': 1, 'b': 2} 

this unpacking available in pythons >= 3.5 introduced pep 448; in previous versions syntaxerror.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -