{"id":29604445,"url":"https://github.com/lguyogiro/betterdict","last_synced_at":"2025-07-20T15:34:27.252Z","repository":{"id":88806093,"uuid":"75986072","full_name":"Lguyogiro/BetterDict","owner":"Lguyogiro","description":"How Python dicts should behave","archived":false,"fork":false,"pushed_at":"2018-05-02T17:53:22.000Z","size":17,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T23:51:09.603Z","etag":null,"topics":["data-structures","dict","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lguyogiro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-09T00:16:45.000Z","updated_at":"2023-04-01T05:03:20.000Z","dependencies_parsed_at":"2023-06-12T18:26:42.786Z","dependency_job_id":null,"html_url":"https://github.com/Lguyogiro/BetterDict","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Lguyogiro/BetterDict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lguyogiro%2FBetterDict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lguyogiro%2FBetterDict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lguyogiro%2FBetterDict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lguyogiro%2FBetterDict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lguyogiro","download_url":"https://codeload.github.com/Lguyogiro/BetterDict/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lguyogiro%2FBetterDict/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266151526,"owners_count":23884436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","dict","python"],"created_at":"2025-07-20T15:34:23.800Z","updated_at":"2025-07-20T15:34:27.246Z","avatar_url":"https://github.com/Lguyogiro.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BetterDicts\nMergeable Python dictionary/OrderedDict/defaultdict/Counter with arithmetic\noperator support.\n\n## Setup\n\n```python\npip install betterdicts\n```\n\n## Examples\n\nUse operator to add, substract, multipy or divide values with like keys.\n\n```python\nfrom betterdicts import BetterDict\n\u003e\u003e\u003e hour1_views = BetterDict({\"user1\": 4, \"user2\": 5, \"user3\": 1})\n\u003e\u003e\u003e hour2_views = BetterDict({\"user4\": 9, \"user2\": 2, \"user6\": 6})\n\u003e\u003e\u003e hour1_views + hour2_views\n{'user1': 4, 'user2': 7, 'user3': 1, 'user4': 9, 'user6': 6}\n```\n\nMerge dictionaries with custom logic:\n\n```python\nfrom betterdicts import BetterDict, merged\n# in-place\n\u003e\u003e\u003e en = BetterDict({1: \"one\", 2: \"two\", 3: \"three\"})\n\u003e\u003e\u003e es = BetterDict({1: \"uno\", 2: \"dos\", 3: \"tres\"})\n\u003e\u003e\u003e en.merge(es, lambda a, b: [a,b])\n\u003e\u003e\u003e en\n{1: ['one', 'uno'], 2: ['two', 'dos'], 3: ['three', 'tres']}\n\n# or return a new, merged BetterDict:\n\u003e\u003e\u003e en = BetterDict({1: \"one\", 2: \"two\", 3: \"three\"})\n\u003e\u003e\u003e es = BetterDict({1: \"uno\", 2: \"dos\", 3: \"tres\"})\n\u003e\u003e\u003e merged(en, es, lambda a, b: [a, b])\n{1: ['one', 'uno'], 2: ['two', 'dos'], 3: ['three', 'tres']}\n```\n\nYou can also perform arithmetic with BetterDicts and scalars:\n\n```python\n\u003e\u003e\u003e raw_counts = BetterDict({'the': 1432, 'she': 600, 'wookie': 25})\n\u003e\u003e\u003e total = 10000.\n\u003e\u003e\u003e relative_freqs = raw_counts / total\n\u003e\u003e\u003e relative_freqs\n{'she': 0.06, 'the': 0.1432, 'wookie': 0.0025}\n\u003e\u003e\u003e relative_freqs * 100\n{'she': 6.0, 'the': 14.32, 'wookie': 0.25}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flguyogiro%2Fbetterdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flguyogiro%2Fbetterdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flguyogiro%2Fbetterdict/lists"}