-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticle 13 python.py
More file actions
42 lines (32 loc) · 893 Bytes
/
practicle 13 python.py
File metadata and controls
42 lines (32 loc) · 893 Bytes
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
36
37
38
39
40
41
42
file = open('a.txt','r')
file1 = open('file1.txt','w')
file2 = open('file2.txt','w')
lineCount = 0
wordCount = 0
charCount = 0
freq = {}
allWords = []
for line in file :
lineCount += 1
charCount += len(line)
words = line.split()
allWords.extend(words)
wordCount += len(words)
for ch in line:
if ch in freq:
freq[ch] += 1
else:
freq[ch] = 1
if lineCount%2 == 0:
file1.write(line)
else:
file2.write(line)
print("Total number of characters : {}".format(charCount))
print("Total number of words : {}".format(wordCount))
print("Total number of lines : {}".format(lineCount))
print("Frequency of each character : ")
for ch in freq.keys():
print("{} : {}".format(ch, freq[ch]))
allWords.reverse()
print("Words in reverse order : ")
print(allWords)