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)
| 56 | |
| 57 | |
| 58 | def compress_dhist(dh): |
| 59 | """Compress a directory history into a new one with at most 20 entries. |
| 60 | |
| 61 | Return a new list made from the first and last 10 elements of dhist after |
| 62 | removal of duplicates. |
| 63 | """ |
| 64 | head, tail = dh[:-10], dh[-10:] |
| 65 | |
| 66 | newhead = [] |
| 67 | done = set() |
| 68 | for h in head: |
| 69 | if h in done: |
| 70 | continue |
| 71 | newhead.append(h) |
| 72 | done.add(h) |
| 73 | |
| 74 | return newhead + tail |
| 75 | |
| 76 | |
| 77 | def needs_local_scope(func): |