Dan McEwan

Programmer, Artist, Historian

Python Challenge [3]

In the third challenge, we’re going to use the str.isLower and str.isUpper functions to find special characters based on case.

First a test run, using a short string and trying to identify where our surrounded character is making his last stand.

alpha = "abCDeFGHiJKLmNopqrStuvwxyz"
for index, char in enumerate(alpha):
	if (char.islower() == 1):
		left = alpha[index-3:index]
		#print left
		if(left.isupper() == 1):
			right = alpha[index+1:index+4]
			#print right
				solution = left + char + right
				print solution 

Then we have the actual solution

import os
mess = open("slop.txt").read()
mess = mess.replace("\n","")
for index, char in enumerate(mess):
        if (char.islower() == 1):
                left = mess[index-3:index]
		leftcap = mess[index-4:index-3]
                #print left
                if(left.isupper() == 1 and leftcap.islower()==1):
                        right = mess[index+1:index+4]
			rightcap = mess[index+4:index+5]
                        #print right
                        if(right.isupper()==1 and rightcap.islower()==1):
                                print char, leftcap,left,right,rightcap

  • Coronet boxes
  • Raid chest
  • Coat rack
  • A Japanese-inspired Cantilever Bench
  • Camp
  • Leaves