[code.view]

[top] / python / PyMOTW / codecs / codecs_invertcaps.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Trivial encoder/decoder that switches capitalization of input characters.
     """
     #end_pymotw_header
     
     import string
     
     def invertcaps(text):
         """Return new string with the case of all letters switched.
         """
         return ''.join( c.upper() if c in string.ascii_lowercase
                         else c.lower() if c in string.ascii_uppercase
                         else c
                         for c in text
                         )
     
     if __name__ == '__main__':
         print invertcaps('ABC.def')
         print invertcaps('abc.DEF')
     

[top] / python / PyMOTW / codecs / codecs_invertcaps.py

contact | logmethods.com