Skip to content

Instantly share code, notes, and snippets.

@josemoralesp
Created March 31, 2017 23:54
Show Gist options
  • Save josemoralesp/aa0de070e7c2e0949d35373c9a8d2b4b to your computer and use it in GitHub Desktop.
Save josemoralesp/aa0de070e7c2e0949d35373c9a8d2b4b to your computer and use it in GitHub Desktop.
from collections import defaultdict
magia = defaultdict(self.env['account.tax'])
for i in self.tax_line_ids:
magia[i.tax_group_id.name] += i
@osvalr
Copy link

osvalr commented Apr 1, 2017

@josemoralesp what about use also dict.fromkeys()?

magia = dict.fromkeys((self.env['account.tax'],))
for i in self.tax_line_ids:
    magia[i.tax_group_id.name] += i

UPDATE

Better to use defaultdict instead of dict.fromkeys(): the first one if a key does not exists wont be turn a KeyError that the second one does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment