I want to find the capital letters in a string at any position, I want that if a string consists of capital letters at any position in a string then against that string "1" should be print and if string does not containing any capital letter at any position then "0" should be print against that string. for this i write a python code but it does not work properly
file='C:/Python26/test.txt'
f=open('letters.txt','w')
pattern='[A-Z+]'
with open(file, 'r') as rf:
for word in rf:
for i in word.split():
if word[0].isupper(): ## finding letters starting with uppercase letters
f.write(word.strip("\n")+"\t"'1'"\n");
elif word.isupper(): ## finding string containing all capital letters
f.write(word.strip("\n")+"\t"'1'"\n");
elif re.search(pattern, word): ## finding string containing capital letter at any position
f.write(word.strip("\n")+"\t"'1'"\n");
else:
f.write(word.strip("\n")+"\t"'0'"\n");
f.close()
my exemplary data is like this
Src
mAB
32DC32
P50
The
activation
fan
.
NFKappaB
IL23RE
cat
.
but my out put is like this
Src 1
mAB 1
32DC32 1
P50 1
The 1
activation 0
fan 0
. 0
1
NFKappaB 1
IL23RE 0
cat 0
.
Which produce wrong result. It does not cater the white space and gave the title "1" and because of this nelection the period (.) did not get any label neither of "0" nor of "1"