Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def weird_encoding(s):
assert(isinstance(s, str))
first = list(s[::-1])
for i, c in enumerate(s):
if c.isupper():
first[i] = first[i].upper()
elif c.islower():
first[i] = first[i].lower()
first = ''.join(first)
second = str(len(s))
tmp = ''
for c in s:
if c.isdigit():
tmp += str(int(c) + 1)
continue
elif c in ('z', 'Z'):
tmp += 'a'
continue
tmp += chr(ord(c) + 1)
if s.isdigit():
third = tmp[::-1]
elif s[-1].isupper():
third = tmp.lower()[::-1]
else:
third = tmp.upper()[::-1]
return first + second + third
if __name__ == '__main__':
print(weird_encoding('Hello'))
print(weird_encoding('LoL'))
print(weird_encoding('123'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.