diff options
| author | root <root@turin.home> | 2022-02-05 18:40:27 +0000 |
|---|---|---|
| committer | root <root@turin.home> | 2022-02-05 18:40:27 +0000 |
| commit | df7e05fea4a14d6749eb476ae4e66b4f2a771a19 (patch) | |
| tree | 8f76b210e10cbb6377f9675a8645a3299700fd20 /dictionary.py | |
| parent | 6671090e31ab30711f169abfb61d880b50ba27d8 (diff) | |
Working on a few last features.
Diffstat (limited to 'dictionary.py')
| -rw-r--r-- | dictionary.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/dictionary.py b/dictionary.py index 32c4e73..9fe1bb4 100644 --- a/dictionary.py +++ b/dictionary.py @@ -33,6 +33,20 @@ class dictionary: self.data.append([key, value]) self.size += 1 + # increment a value + def inc(self, key, value=1): + # defensive programming + in_data = False + i = 0 + # high efficiency loop stops after found + while i < self.size and in_data == False: + if self.data[i][0] == key: + self.data[i][1] += value + in_data = True + i += 1 + if not in_data: + self.add(key, value) + # Sort dictionary by value def sort_by_value(self): self.data = sort_v(self.data, self.size, 1) |
