Python Task on Objects and Algorithms

Python Task on Objects and Algorithms

files=[“in_abc10.txt”,”in_abc100.txt”]
outFiles=[“out_abc10a.txt”,”out_abc100a.txt”]
finalOutputFile=[“out10b.txt”,”out100b.txt”]

alphabets=[“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,
“v”,”w”,”x”,”y”,”z”]
wordLen=[“01″,”02″,”03″,”04″,”05″,”06″,”07″,”08″,”09″,”10″,”11″,”12″,”13″,”14″,”15″,”16″,”17″,”18”,
“19”,”20″,”21″,”22″,”23″,”24″,”25″,”26″]
wordLength=0
def sort(line):

if(len(line)>0):
word=line.split()
converted=[]
ch=””

for i in word:
for j in i:
for k in range(0,len(alphabets)):
if(alphabets[k]==j):
ch+=wordLen[k]

if(len(ch)<wordLength):
for i in range(0,wordLength-len(ch)):
ch+=”0″
converted.append(ch)

ch=””

#sorting done here
for i in range(len(converted)-1):
for j in range (0,len(converted)-i-1):
if(int(converted[j])>int(converted[j+1])):
converted[j],converted[j+1]=converted[j+1],converted[j]
word[j],word[j+1]=word[j+1],word[j]
fin=” ”

for i in range(0,len(word)):
if(len(word[i])<3):
for j in range (0,3-len(word[i])):
word[i]+=” ”
return fin.join(word)
return “”
temp=0
for i in files:
fp=open(i,”r”)
fpOut=open(outFiles[temp],”w”)
line=fp.readline()
splitLine=line.split(“=”)
word=splitLine[1].replace(“\n”,””)
word=word.replace(” “,””)
wordLength=len(word)*2

fullData=””
while(line):
line=fp.readline()
line=line.lower()
line.replace(“\n”,””)
fullData+=line
fullData+=” ”
newLine=sort(fullData)

fpOut.writelines(newLine)
fpOut.writelines(“\n”)

temp+=1
fp.close()
fpOut.close()
temp=0
for i in files:
fp=open(i,”r”)
fpOut=open(finalOutputFile[temp],”w”)
line=fp.readline()
totalData=””
while(line):
line=fp.readline()
if(len(line)>0):
line=line.lower()
line=line.replace(“\n”,””)
totalData+=line
totalData+=” ”

words=totalData.split(” “)
words=[i for i in words if i]
words.sort()
newline=””
for i in range(0,len(words)):
if(len(words[i])<3):
for j in range (0,3-len(words[i])):
words[i]+=” ”
for i in words:
newline+=i
newline+=” ”
fpOut.writelines(newline)
fpOut.writelines(“\n”)

temp+=1
fp.close()
fpOut.close()