Compress a directory history into a new one with at most 20 entries. Return a new list made from the first and last 10 elements of dhist after removal of duplicates.
(dh: list[str])
| 65 | |
| 66 | |
| 67 | def compress_dhist(dh: list[str]) -> list[str]: |
| 68 | """Compress a directory history into a new one with at most 20 entries. |
| 69 | |
| 70 | Return a new list made from the first and last 10 elements of dhist after |
| 71 | removal of duplicates. |
| 72 | """ |
| 73 | head, tail = dh[:-10], dh[-10:] |
| 74 | |
| 75 | newhead: list[str] = [] |
| 76 | done: set[str] = set() |
| 77 | for h in head: |
| 78 | if h in done: |
| 79 | continue |
| 80 | newhead.append(h) |
| 81 | done.add(h) |
| 82 | |
| 83 | return newhead + tail |
| 84 | |
| 85 | |
| 86 | def needs_local_scope(func: _F) -> _F: |