quantifiedcode / python-anti-patterns

An open collection of Python anti-patterns and worst practices.
https://quantifiedcode.github.io/python-anti-patterns
Other
1.71k stars 249 forks source link

New Antipattern: Not using dict keys when formatting strings. #44

Closed Brobin closed 9 years ago

Brobin commented 9 years ago

New antipattern that I've found very useful and vastly improves readability.

person = {'first':'Tobin', 'last': 'Brown', 'age':20}

print('{0} {1} is {2} years old'.format(person['first'], person['last'], person['age']))  # bad

print('{first} {last} is {age} years old'.format(**person))  # good