9đź‘Ť
Python 3.0 has dict comprehensions as a shorter/more readable form of the anser provided by Steef:
errs = {f.auto_id: f.errors for f in form if f.errors}
👤Steven
- [Django]-Django [Mezzanine CMS] project not deploying to Heroku
- [Django]-Django global filter
- [Django]-Django – ManyToMany as hidden fields?
- [Django]-Relational DatabaseError in django postgresql database after deploying project to bitnami
- [Django]-How do I successfully pass variables to my python social auth pipeline?
4đź‘Ť
It probably could be, but as per the “Readability counts.” rule (PEP 20), I’d say it’s a bad idea. 🙂
On the other hand you have “Flat is better than nested.” and “Sparse is better than dense.”, so I guess it’s a matter of taste 🙂
👤mikl
0đź‘Ť
Both ways are quite readable, however you should think of future maintainers of the code. Sometimes explicit is better. List comprehensions rule though 🙂
👤Nick Martin
- [Django]-Django filter queryset by attribute subclass
- [Django]-Sublime text 3 Anaconda goto definition not working with Django
- [Django]-Your models have changes that are not yet reflected in a migration
- [Django]-OAuth2 specification states that 'perms' should now be called 'scope'. Please update. Django Facebook connect
Source:stackexchange.com