-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomework2.py
57 lines (55 loc) · 2.34 KB
/
Homework2.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 8 17:43:06 2018
@author: Harsha Vardhan Manoj
"""
#Ending in ize
#Containing the letter z
#Containing the sequence of letters pt
#Having all lowercase letters except for an initial capital (i.e., titlecase)
import nltk
from nltk.book import *
text = open("answer.txt","w")
Ending_in_ize=[]
Containing_letter_z=[]
Containing_sequence_pt=[]
Containinge_pt=[]
Titlecase=[]
list_Tokens=list(text6)
for token in list_Tokens:
length=len(token)
if(length >= 3):
if (token[length-1]=='e' and token[length-2]=='z' and token[length-3]=='i'):
Ending_in_ize.append(token)
if('z' in token):
Containing_letter_z.append(token)
if('pt' in token):
Containinge_pt.append(token)
if('p' in token and 't' in token):
p_position=token.find('p')
t_position=token.rfind('t');
if(t_position > p_position):
Containing_sequence_pt.append(token)
if(token[0].isupper() and token[1:].islower()):
Titlecase.append(token)
text.write("Tokens ending in \"ize\" are and no.of tokens are "+str(len(Ending_in_ize))+" :\n\n\n")
for print_token in Ending_in_ize:
text.write(print_token+' , ');
text.write("\n===================================================\n")
text.write("Tokens having pt adjacent are and no.of tokens are "+str(len(Containinge_pt))+" :\n\n\n")
for print_token in Containinge_pt:
text.write(print_token+' , ');
text.write("\n===================================================\n")
text.write("Tokens Containing letter z are and no.of tokens are "+str(len(Containing_letter_z))+" :\n\n\n")
for print_token in Containing_letter_z:
text.write(print_token+' , ');
text.write("\n===================================================\n")
text.write("Tokens sequence of letters pt are and no.of tokens are "+str(len(Containing_sequence_pt))+" :\n\n\n")
for print_token in Containing_sequence_pt:
text.write(print_token+' , ');
text.write("\n===================================================\n")
text.write("Tokens Having all lowercase letters except for an initial capital are and no.of tokens are "+str(len(Titlecase))+" :\n\n\n")
for print_token in Titlecase:
text.write(print_token+' , ');
text.write("\n===================================================")
text.close()