From 181fe0922f02017c5d85837dd3d5ce33fc8c6c48 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 26 Feb 2020 12:13:38 +0000 Subject: - Added Python solution by Orestis Zekai. --- challenge-049/orestis-zekai/python/ch-2.py | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 challenge-049/orestis-zekai/python/ch-2.py diff --git a/challenge-049/orestis-zekai/python/ch-2.py b/challenge-049/orestis-zekai/python/ch-2.py new file mode 100644 index 0000000000..21ac9b66d5 --- /dev/null +++ b/challenge-049/orestis-zekai/python/ch-2.py @@ -0,0 +1,37 @@ +capacity = 3 +cache = [None for x in range(capacity)] +print(cache) + +def get(pos): + global cache + if (pos > capacity - 1): + return -1 + val = cache[pos-1] + shift(pos) + return val + + +def set(pos, n): + global cache + cache[pos-1] = n + + +def shift(pos1): + global cache + temp = cache.pop(pos1-1) + cache.append(temp) + + +set(1, 3) +print(cache) +set(2, 5) +print(cache) +set(3, 7) +print(cache) + +print(get(2)) +print(cache) +print(get(1)) +print(cache) +print(get(9)) +print(cache) \ No newline at end of file -- cgit