Code Snippets

  

Linux & UNIX Source Code

  

Python Source Code



Character Flipper

For each character in any string, if the letter is capitalized, it makes it lowercase, and for any capital letters, make them lowercase.

Submitted By: Dogstopper
Actions:
Rating:
Views: 1,478

Language: Python

Last Modified: February 8, 2010
Instructions: Nothing special. Made for Python 2.6

Snippet


  1. def invert():
  2.     original = raw_input(">> ")
  3.     newStr = ''
  4.     for char in original:
  5.  
  6.         # Take care of lowercase letters
  7.         if char.islower():
  8.             newStr += char.upper()
  9.  
  10.         # Take care of capital letters
  11.         elif char.isupper():
  12.             newStr += char.lower()
  13.  
  14.         # Takes care of punctuation
  15.         else:
  16.             newStr += char
  17.  
  18.     print newStr

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.