Skip to content

Instantly share code, notes, and snippets.

@Zomatree
Created June 25, 2020 13:04
Show Gist options
  • Save Zomatree/f3ad9f9ae081a146a2ad6a5d00b1950a to your computer and use it in GitHub Desktop.
Save Zomatree/f3ad9f9ae081a146a2ad6a5d00b1950a to your computer and use it in GitHub Desktop.
import string
class CyclicList(list):
def __getitem__(self, x):
index = x.__index__()
return super().__getitem__(index % len(self))
l = CyclicList(string.ascii_lowercase+string.punctuation+string.whitespace)
inp = input("Enter text: ").lower()
if not all(char for char in inp if char in l):
raise TypeError("Not all letters")
shift = int(input("Enter amount to shift by: "))
print("".join(map(lambda char: l[l.index(char)+shift], inp)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment