DEV Community

Discussion on: Daily Challenge #42 - Caesar Cipher

Collapse
 
hectorpascual profile image

Python :

def cypher(m, key):
    m_cypher = ''
    for i in m:
        if i != ' ' and i != '.':
            m_cypher += chr(ord(i) + key)
        else:
            m_cypher += i
    return m_cypher

One line :

cypher = lambda m, key : ''.join(chr(ord(i) + key) if i != ' ' and i != '.' else i for i in m)