forked from benesch/crimsononline-assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swapchar.py
35 lines (33 loc) · 822 Bytes
/
swapchar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import sys
def swapchar(str):
charslist=[str[0]]
numslist=[0]
found=0
for c in str:
for i in range(len(charslist)):
if (charslist[i]==c):
numslist[i]=numslist[i]+1;
found=1;
if (found==0):
charslist.append(c);
numslist.append(1);
found=0;
maxindex=0
minindex=0
for i in range(len(numslist)):
if (numslist[i]>numslist[maxindex]):
maxindex=i;
if (numslist[i]<numslist[minindex]):
minindex=i;
maxchar=charslist[maxindex]
minchar=charslist[minindex]
for c in str:
if (c==maxchar):
sys.stdout.write(minchar);
elif (c==minchar):
sys.stdout.write(maxchar);
else:
sys.stdout.write(c);
sys.stdout.write('\n');
swapchar("There were a lot of escopeoples in the elevator on Tuesday.");